Using VisualStateManager inside DataTemplate

January 6, 2016 Leave a comment

Adaptive layout is really important while we creating windows universal apps and the
recommended way to achieve it is using RelativePanels and VisualStateManager.VisualStateGroups.

On a normal static page [where data is fixed or known for us] we can achieve it easily.
But if we are delaing with adynamic list of data or if we bind thda data to a listbox or any list its bit different.

Important point here is

we can’t directly use Adaptive concept using VisualStateManager.VisualStateGroups with objects placed inside a DataTemplate. Instead, we need to create a User Control and put the DataTemplate content inside it:

A detailed blog with proper explanation is here and it helps me a lot with my development

Categories: Prsnl References Tags: ,

Remove Frame rate counters or black rectangles from corners while running Universal windows app

January 4, 2016 Leave a comment

While i started the development on Universal windows app and when i run the UWP app on Local machine or on emulator i noticed a black rectangle on the top right corners of application like in the image


After reading few more about UWP i  realized that this is indication of frame rates and we can disable it. So to disable this Frame rate indication while running the application what we have to do is disable few lines of code from the  OnLaunched event in App.xaml.cs file

   #if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
this.DebugSettings.EnableFrameRateCounter = true;

Categories: Prsnl References Tags: ,

basic enum parsing in c#

October 9, 2015 Leave a comment

Below script helps to parse a enum value and handle unexpected values

CustomEnumXXX enum_var;
if (Enum.TryParse(stringvalueEnumYYYYY, out enum_var))
enum_var has the parsed correct value
eerror while parsing

Categories: Prsnl References

Generate word documents using OpenXML SDK

October 22, 2014 Leave a comment

Recently i came across a requirement that the application allows the user to generate the word documents for a specific report and they want the same data must follow some specific patterns .

So creating word document from scratch makes no sense and thus i forced to start look for other alternate options and came to know about OpenXML . But  only few limitted resources are available over the internet that explains the usage of this in a neat easy way fit perfect for begginers 


Both these are explain the concept using a desktop applicaton , but any one can easily convert it back to web app. In case th blog Urls are down can see the details of the blog in attached PDF

OpenXML Éric Moreau’s blog _ Using OpenXML to fill a Word document from a OpenXML Word templates processing _ dotNet Geek _

Categories: Prsnl References Tags: , ,

WPF POPUP control with Drag and Drop support and Resize support

May 27, 2014 Leave a comment

To enable DragDrop support follow the steps

Add namespace System.Windows.Interactivity; in WPF project

Creates a class like this

public class MouseDragPopupBehavior : Behavior<Popup>
        private bool mouseDown;
        private Point oldMousePosition;

        protected override void OnAttached()
            AssociatedObject.MouseLeftButtonDown += (s, e) =>
                mouseDown = true;
                oldMousePosition = AssociatedObject.PointToScreen(e.GetPosition(AssociatedObject));
            AssociatedObject.MouseMove += (s, e) =>
                if (!mouseDown) return;
                var newMousePosition = AssociatedObject.PointToScreen(e.GetPosition(AssociatedObject));
                var offset = newMousePosition – oldMousePosition;
                oldMousePosition = newMousePosition;
                AssociatedObject.HorizontalOffset += offset.X;
                AssociatedObject.VerticalOffset += offset.Y;
            AssociatedObject.MouseLeftButtonUp += (s, e) =>
                mouseDown = false;

IN Xaml redesign popup like this

 xmlns:myControl=”clr-namespace:use ur name space”


And design popup like

                    …..  Fil popup contents here….     

To support resize  we need to add few more things .

First redesign popup like

<Popup   Name=”popupname” …>
                    —-popup contents—
                    <Thumb HorizontalAlignment=”Right” VerticalAlignment=”Bottom” Width=”16″ Height=”16″
                              DragStarted=”onDragStarted” DragDelta=”onDragDelta” DragCompleted=”onDragCompleted”/>


And in c# write events

  private void onDragStarted(object sender, DragStartedEventArgs e)
            Thumb t = (Thumb)sender;
            t.Cursor = Cursors.Hand;

        private void onDragDelta(object sender, DragDeltaEventArgs e)

            double yadjust = this.popupname.Height + e.VerticalChange;
            double xadjust = this.popupname.Width + e.HorizontalChange;
            if ((xadjust >= 0) && (yadjust >= 0))
                this.popupname.Width = xadjust;
                this.popupname.Height = yadjust;

        private void onDragCompleted(object sender, DragCompletedEventArgs e)
            Thumb t = (Thumb)sender;
            t.Cursor = null;

Categories: Prsnl References Tags:

MVC3 Load enumerator in a dropdown and set as selected in edit mode

April 29, 2014 Leave a comment

ViewModel class: Syntax: In your view model calss make 2 properties
[Display(Name = “Fee Type”)]
public SchoolApp.EnumValues.FeeTypeValues FeeType { get; set; }

public List<SelectListItem> FeeTypeOptions { get; set; }

FeeHeaderModel model = new FeeHeaderModel();
model.FeeTypeOptions = getFeeTypeOptions();

public List<SelectListItem> getFeeTypeOptions()
    string[] names = Enum.GetNames(typeof(FeeTypeValues)); //ur enum vvalues here
    List<SelectListItem> _licenceItems = new List<SelectListItem>();
    foreach (string _value in names)
        _licenceItems.Add(new SelectListItem
            Text = _value,
            Value = _value
    return _licenceItems;

In edit mode set selected value by using the below code
    model.FeeType = (SchoolApp.EnumValues.FeeTypeValues)Enum.Parse(typeof(SchoolApp.EnumValues.FeeTypeValues), dbItem.FeeType, true);
    model.FeeType = SchoolApp.EnumValues.FeeTypeValues.Common;
Razor view syntax:
<div class=”form-group”>
    @Html.LabelFor(model => model.FeeType)      
    @Html.DropDownListFor(model => model.FeeType,Model.FeeTypeOptions, new { @class = “form-control” })
    @Html.ValidationMessageFor(model => model.Amount)

Categories: Prsnl References Tags:

MVC5 Custom Authentication

March 12, 2014 Leave a comment

Found an article explained about the way to implement mvc5 form based authentication here

and its very useful

Categories: Prsnl References