.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Event Binding in MVVM

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :WPF
We are implementing the MVVM in the WPF forms that we are designing. For this we have designed the specific ViewModels for each WPF view. The WPF form has various controls such as button, combo box etc. We are registering the button click event and other events in the ViewModel constructor. Is there better way of handling this? Pls.guide

View Complete Post

More Related Resource Links

Basic Instincts: Static Event Binding Using WithEvents


This month's Basic Instincts column builds upon my last three columns in which I introduced and explained the fundamental concepts and syntax associated with delegates and events. Last month I showed you how to design and write a simple class that defines and raises events.

Ted Pattison

MSDN Magazine March 2003

Event Binding


Where do i define list affinity of my event?

I though it was "Receivers ListTemplateId" in elements.xml. But when i changed it from 100 (custom list) to 140 and redemployed feature nothing changed. Event still is firing on custom list event and stays still on 140 (workflow history) list events (


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="140">

Binding an event method from a control in a seperate window

How would you bind a event method from a control back to a seperate window?  I have a ActiveX control hosted in a WindowsFormsIntegration wrapper.  That is operating in its own window along with all its events.  The properties of the control are handled by a class that defines the dependency objects (thanks Bob) to provide a view model between it and a window with controls for setting/getting those properties.  Since events constrained to Window 2, is it possible to bind the events back to Window 1?

Binding event or interacting with WorkflowDesignSurface in Workflow Monitor

Is there any way to modify the sample Workflow Monitor class so the user can interact with the diagram, for example;    1) being able to select an activity in the diagram and get back an event of which activity was selected? and/or 2) being able to trigger an if else branch by clicking on the diagram. Any pointers to howtos/tutorials will be helpful, thanks!

Design binding help with MVVM

Dear all, I have the follwoing View model which collect a list of Winners from a database define as follow :  public class WinnersViewModels : DependencyObject { public WinnerSet WinnerSet{get;set;} public CollectionView WinnersCollection { get; set; } public WinnersViewModels() { WinnerSet = new WinnerSet(); WinnerSet.CallRandomWinners(); WinnersCollection = (CollectionView)CollectionViewSource.GetDefaultView(WinnerSet.Winners); } }  WinnerSet is a simple class which collect information from a Winner and Winners a collection of WinnerSet as follow : public class WinnerSet { private string connectionString = string.Empty; public string FirstName {get;set;} public string LastName { get; set; } public string Company { get; set; } public Winners Winners { get; set; } ....... } public class Winners : ObservableCollection<WinnerSet> { } What I need to do out of this is to be able to add in  a list box the list of Winners return by the WinnersViewModels. For that I have define a user control which define my different fields like firstName, LastName, Company and set dynamically the content of the listbox Item to be my user control and the datacontext to be the current item. Doing so my user control appears in the list box but the binding do not occu

Binding DataGrid RowDetailTemplate Using MVVM

In this post I will show you how you can bind the RowDetailTemplate of the data grid using the MVVM pattern. Below are the image of the sample code here you can see the default page in Image 1 and when user click on any of the record then detail of the record is shown in the RowDetailTemplate which also consist of the data grid control which you can see in the Image 2.

Binding ListView Control Using MVVM

In this short post I will show you how you can bind the list view control and get the selected value of the list view control using MVVM pattern. For this post I have added one list view control which hold the grid view control in it view and when item is selected in the grid view the selected item is shown at the end of the screen. In the Image 1the selected items are not shown ( only the label fields are shown) but in the Image 2 when user click on any of the item the detail is shown.

MVVM how to move event handler from code behind to ViewModel


First of all I'm fairly new to WPF and MVVM. For learning purposes I created a very simple MVVM test app similar to the one demonstrated here: http://windowsclient.net/learn/video.aspx?v=314683

I am trying to find out how to work with events in the MVVM pattern. To work with events in the xaml code behind is simple. But how to move the code to the ViewModel?

In the xaml I have:

    <StackPanel Background="{Binding BackgroundBrush}">
        <ItemsControl ItemsSource="{Binding AllEmployees}">
                    <StackPanel Orientation="Horizontal">
                        <TextBox Width="100" Text="{Binding FirstName}" />
                        <TextBox Width="100&q

DataForm EditTemplate Binding MVVM


Hi, I didn't found an active Silverlight formun , so I post my question here.

I have a problem trying to bind a property of my viewmodel from a DataForm EditTemplate template.

My Model and My ViewModel are:

 public class PersonViewModel
 public Person PersonBase { get; set; }
 public string OtherData { get; set; }
 public class Person
 public string Name { get; set; }
 public string Phone { get; set; }

My View is: 

 <StackPanel x:Name="LayoutRoot">
 <TextBlock>Other Data</TextBlock>
 <TextBox BorderBrush="Red" BorderThickness="1" Text="{Binding OtherData}"></TextBox>
 <toolkit:DataForm CurrentItem="{Binding PersonBase}"
   <toolkit:DataField Label="OtherData">
    <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=OtherData}"></TextBlock>
   <toolkit:DataField Label="Name">
   <TextBox Text="{Binding Name}"></

Binding an event handler to a list



I am trying to bind an event handler to a list using the following code. I have the same code before with success, but I am not sure why it is not binding it anymore. Also I am getting no error, but the event is not firing when I bind the event handler using the following code:


static void Main(string[] args)
      int check = 1;
        SPSite collection = new SPSite("https://fullsitepathhere");
        Console.WriteLine("Working - 1");
        check = 3;
        SPWeb site = collection.OpenWeb();
        Console.WriteLine("Working - 2");
        check = 4;
        SPList temp = site.Lists["Data Storage"];
        Console.WriteLine("Working - 3");
        check = 2;

        string assname = "NewSaas, Version=, Culture=neutr

Need help on Data binding with DPs and Control Loaded event



I have a very interesting issue and i have been breaking my head on it since a long time.

I am new to WPF and related things like MVVM and all.

I have a window in which i place a user control which hosts a TabControl inside it.

This tab control has Custom Radio Button and Combo boxes which expose few Dependency Properties, Now while these custom controls are loaded author checks for the values and does 'something particular' which is intended behavior. However in my case while the control is being loaded the DPs have null values. I see the DP property changed events being fired post Load of that control only in my case. It works okay on other windows.

This is kind of strange to me as I would expect that the DPs would be bound to related values before the control gets loaded, but i dont see that behaviour here.

 I have read on MSDN that the DPs should be set properly before load event, and in a sample application i see it behaving as per MSDN.

Binding is happening properly as there are no errors in out put window + I get the DP - Property changed events as well, but this happens only after load (I dont know why??)

Any help would really be appreaciated.



WPF Toolkit Calendar, Blackout Dates, DataTemplate, Binding, MVVM



I am building an application using the MVVM model and I'd like to bind a calendar's "BlackoutDates" collection. I found this interesting piece of code which shows how to achieve this binding through an Attached Property. I am using the WPF ToolKit at codeplex.

However as I understand it, I need to bind to a "CalendarBlackoutDatesCollection" property. Ideally, this property would be in my ViewModel so that i can use {Binding BlackoutDates} however, the constructor for CalendarBlackoutDatesCollection has to specify the "owner", or the calendar that will receive this collection, which my ViewModel doesn't know about.

The calendar is actually part of a DataTemplate so I can't just name it and reference it directly. I'm saying this because I tried a workaround solution through events in the code behind file. The simplest of my scenario involves 2 calendars in the same data item (a "from" and a "to" calendar). When the user clicks on a "From" date, then all prior dates are blacked out in the "To" calendar to prevent the user from entering a time range backwards. The same applies if a user selects a "To" date - anything after that

AutoComplete TextChanged Or LostFocus event for MVVM Windows APP


AutoComplete TextChanged Or LostFocus event for MVVM Windows APP


Can any one help me ..


<toolkit:AutoCompleteBox Grid.Column="1" Grid.Row="1" Margin="2" 

                    ItemsSource="{Binding VendorMasterList}" MaxDropDownHeight="250"

                    FilterMode="StartsWith" IsTextCompletionEnabled="True" Visibility="Visible"

                    Text="{Binding StandardName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

                    IsEnabled="{Binding IsReadOnlySup}" 

                    SelectedItem="{Binding SelectedVendoerMaster,Mode=TwoWay}">




AutoComplete LostFocus event for MVVM Application


Any One can help me I have done most part of it except one place i struck



public class AutoLostFocus :AutoCompleteBox , IDisposable 


        public static readonly DependencyProperty LostFocusBehaviourProperty =

            DependencyProperty.RegisterAttached("LostFocusBehaviour", typeof(LostFocusEventManager),

            typeof(AutoCompleteBox), new UIPropertyMetadata(""));


        public static readonly DependencyProperty CommandProperty =

            DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(LostFocusEventManager), new UIPropertyMetadata(""));


        public static ICommand GetCommand(AutoCompleteBox control)


            return (ICommand)control.GetValue(CommandProperty);




Binding Command Inside DataGrid Using MVVM

In this post I will show you how to bind the commands inside the data grid control using MVVM pattern. For this post I have continue my last post which is used to explain the data pager using MVVM. For this post I have added DelegateCommand class which is added in the Classes folder. I have only one command in the viewModel (with the name HomeViewModel and is located in the ViewModel folder). The view for the Home is located in the View folder. Here you can see that I have added the HomeViewModel as resource in the home view which you can see in the Image 1.

WPF: If Heineken did MVVM Frameworks Part 4

MVVM is to have an instance of a particular Model (say currentPerson) inside my ViewModel (say PeopleViewModel) which is exposed to the View (say PeopleView). The View binds and edits the Model directly.

This definitely flies in the face of what most people consider to be the holy grail of MVVM pattern, but it's a fairly new pattern, so people are still finding their way with it every day, and this works for me very well. The reason I do what I do, is for the following reasons:

1.I have always had the luxury of being able to write my own UI specific Model classes. I would even do this if I was using some other Model classes first, such as LINQ to SQL or LINQ to Entity Framework. As these classes don't have everything a proper WPF Model class needs in my humble opinion. Though, they are pretty good, as they are Partial classes and use INotifyPropertyChanged/DataContract etc etc
2.I am a pragmatist and I do not like writing code for the sake of writing code. I have seen some MVVM apps where the author has had a Model with 50 properties on it, that are simply repeated in the ViewModel abstraction, where the ViewModel added nothing. On that day I decided I would never do that unless I have to.
3.I honestly see no harm in writing directly to the Model from the View, JUST SO LONG AS if the Model is InValid its data NEVER makes its way to the database. I honestly see no pro

Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend