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

https://marcominerva.wordpress.com/2015/05/12/adaptive-triggers-relativepanel-and-datatemplate-in-universal-windows-platform/

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

blog_framerate

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;
}
#endif

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
}
else
{
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

http://www.dotnet-geek.co.uk/index.php/openxml-word-templates-processing/ 

and http://www.emoreau.com/Entries/Articles/2011/03/Using-OpenXML-to-fill-a-Word-document-from-a-Net-application.aspx

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.Child.CaptureMouse();
            };
            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;
                AssociatedObject.Child.ReleaseMouseCapture();
            };
        }
    }

IN Xaml redesign popup like this

 xmlns:myControl=”clr-namespace:use ur name space”
xmlns:i=”http://schemas.microsoft.com/expression/2010/interactivity&#8221;

 

And design popup like

   <Popup………………….>
                <i:Interaction.Behaviors>
                    <myControl:MouseDragPopupBehavior/>
                </i:Interaction.Behaviors>   
                    …..  Fil popup contents here….     
            </Popup>

To support resize  we need to add few more things .

First redesign popup like

<Popup   Name=”popupname” …>
                <i:Interaction.Behaviors>
                    <myControl:MouseDragPopupBehavior/>
                </i:Interaction.Behaviors>
                <Grid>
                    —-popup contents—
                    <Thumb HorizontalAlignment=”Right” VerticalAlignment=”Bottom” Width=”16″ Height=”16″
                              DragStarted=”onDragStarted” DragDelta=”onDragDelta” DragCompleted=”onDragCompleted”/>
                </Grid>
            </Popup>

 

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”)]
[Required]
public SchoolApp.EnumValues.FeeTypeValues FeeType { get; set; }

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

Controller
———
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
try
{
    model.FeeType = (SchoolApp.EnumValues.FeeTypeValues)Enum.Parse(typeof(SchoolApp.EnumValues.FeeTypeValues), dbItem.FeeType, true);
}
catch
{
    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)
</div>

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

http://www.khalidabuhakmeh.com/asp-net-mvc-5-authentication-breakdown-part-deux

and its very useful

Categories: Prsnl References