Archive

Archive for the ‘Prsnl References’ Category

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

Customization on WPF ListView

June 5, 2013 2 comments

If  some one is planning to simply bind a list of datas to a listview in WPF its pretty easy and straight forward. But today i came through a case where i need a listbox that supports Sorting , Inline Editting and Save the chages to Db once i finish the inline edit .

I started one by one  1. Sorting and Inline Editting  > Using the logic or idea from this blog http://tech.pro/tutorial/857/wpf-tutorial-using-the-listview-part-3-in-place-edit

2. Saving the changes after finish the edit operation to Db – Add a new event to the textbox where you want to edit the data and do actions on that event

LostFocus=”textWordDescription_LostFocus” Tag=”{Binding}”

             string newtext = ((TextBox)sender).Text;
BindedObject selected = ((TextBox)sender).Tag as BindedObject;
updateDetails(selected.Id,selected);

Then next challenge is  want to sort my datas in ascending order . The following code solves that issue

  private void Sort(string sortBy, ListSortDirection direction)
{
ICollectionView dataView =
CollectionViewSource.GetDefaultView(wordBankListView.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}

Next Challenge is with selection . By default i want to select an item in listbox (Its  pretty easy thing . just set selectedvalue ). But i need to handle the position of scrollviewer as well . If 100 items in listbox and i selected an item starts with letter z then thae item is in bottom of list , So using this code i make sure the scrollviewer position is closer to selected wordSystem.Windows.Controls.Primitives.Selector selector = wordBankListView;
(selector as ListBox).ScrollIntoView(selector.SelectedItem);

Categories: Prsnl References Tags: ,

MVC Models in LINQtoSQL way

December 21, 2012 Leave a comment

ASPNET_MVC_Tutorial_10_CS

A sample tutorial i found while learning LINQ2SQL in MVC3 . Dont remember the resource owner or source site, But is really a useful post

Categories: Prsnl References Tags: ,

Async. Download progress bar c#

December 4, 2012 Leave a comment

The code for creating an async. download progress bar , allows user to track how much data is downloaded

WebClient client = new WebClient();

client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);

client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

//// Starts the download

string folder_path =”Location to save file”;

client.DownloadFileAsync(new Uri(downloadUrl), folder_path,””);

void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

{

double bytesIn = double.Parse(e.BytesReceived.ToString());

double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());

double percentage = bytesIn / totalBytes * 100;

 

downloadProgress.Text = int.Parse(Math.Truncate(percentage).ToString()).ToString()+” % finished”;

}

Categories: Prsnl References Tags: , , , ,