.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

Design binding help with MVVM

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :WPF
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

View Complete Post

More Related Resource Links

Data Binding: Give Your Everyday Custom Collections a Design-Time Makeover


In this article, Paul Ballard shows how you can provide data binding support for your custom collections to enable sorting, searching, and editing in as simple a manner as possible. In addition, he shows how to make all of these features available in the Windows and Web Forms Designers, just like an ADO.NET DataSet.

Paul Ballard

MSDN Magazine August 2005

Event Binding in MVVM

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

Binding WPF grid to ViewModel : Suggest the design

I have structure like this I have following structure BaseViewModel ViewModel1: BaseviewModel ViewModel2: BaseViewModel In grid i will be showing the data from both the ViewModel1 and ViewModel2 (some common data is there ) How should i go about this Expected functionality : IF i select any row in the grid i should get respective ViewModel    

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.

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}"></

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

EF Binding to DataGrid at design time in VS2010


I'm playing arround with the DataGrid for wpf and EF in Visual studio 2010.
The easiest way to bind is to set the ItemsSource="{Binding} and in the Window_Loaded event MyDataGrid.DataContext = efData.SomeData
It is working fine, but I don't have data at design time.
Is there an easy way todo?


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

Abstract Factory Design in C# , Vb.NET

Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Prototype Design Pattern in C#. Vb.NET

Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype

Adapter Design Pattern in C#, VB.NET

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Singleton Design Pattern in C#, Vb.NET

Ensure a class has only one instance and provide a global point of access to it.

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.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Solidify Your C# Application Architecture with Design Patterns

design pattern can solve many problems by providing a framework for building an application. Design patterns, which make the design process cleaner and more efficient, are especially well-suited for use in C# development because it is an object-oriented language. Existing design patterns make good templates for your objects, allowing you to build software faster. This article describes several popular design patterns you can use in your own applications, including the singleton, the decorator, the composite, and the state classes, which can improve the extensibility of your applications and the reuse of your objects.
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