.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

DataForm EditTemplate Binding MVVM

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :WPF

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

View Complete Post

More Related Resource Links

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

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.

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

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.

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

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.

WPF / Silverlight tutorial: Visibility property and binding

Visibility property is a very powerful and yet often overlooked property available in both WPF and Silverlight. It enables you to set Visibility of certain UIElement objects to different states like: Visible, Collapsed and Hidden (not supported by Silverlight). This tutorial shows you how to use it and how to bind to Visibility property

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Binding Nested Listviews in MVC ViewPage


I am a longtime .NET developer but for big applications and services.  This is my first asp.net project and I have chosen MVC.   I have a need for nesting a ListView within a ListView.  In this simple catalog app, I have EF 4 Entities that are Categories, SubCategories, ItemTypes, and Items.

My goal is to display a 5 column layout of SubCategories with their ItemTypes below them in a ViewPage.  I did just fine with it done out in C# as server directives such as:

    var subcats = Model.SubCategory.ToArray();
    var nrSubCats = subcats.Count();
    var rows = (nrSubCats/5) + (((nrSubCats % 5) > 0) ? 1 : 0);
    for (var row = 0; row < rows; row++)
    { %>
        <div style="width: 100%; float: left; clear: right;">
        var start = row * 5;
        for (var i = start; (i < start + 5) && (i < nrSubCats); i++)
        var subcat = subcats[i];
            <div style="float: left; clear: right; width: 20%; margin-left: 5;">
                <h2> <%:subcat.Name%></h2>
                    foreach (var its in subcat.ItemType)

Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

Can I use MVVM for it?


I've read many articles about MVVM, but I can't get it into real code.

I have two lists which have common field user_id. First list contains all users with their names and second all files from all users. The asp.net page should show grid with newest file for every user. How can I get it into MVVM? Where should I bind username to his file? Need I ViewModel for every list or one common for both?


Regards, Gabriel

Error while adding pollingduplex binding


I am making samle of polling duplex in .net 4.0

when ever i put binding this tag in web.config it shows error.


Warning    1    The element 'bindings' has invalid child element 'pollingDuplexHttpBinding'. List of possible elements expected: 'basicHttpBinding, customBinding, msmqIntegrationBinding, netPeerTcpBinding, netMsmqBinding, netNamedPipeBinding, netTcpBinding, wsFederationHttpBinding, ws2007FederationHttpBinding, wsHttpBinding, ws2007HttpBinding, wsDualHttpBinding, netTcpContextBinding, wsHttpContextBinding, basicHttpContextBinding, mexHttpBinding, mexHttpsBinding, mexNamedPipeBinding, mexTcpBinding, webHttpBinding'.    D:\DuplexTest\TestPollingDuplexWcf\TestPollingDuplexWcf\TestPollingDuplexWcf\Web.config    9    8    TestPollingDuplexWcf

var Transliterate = { loaded: false, // HRef is_local:false, is_write:false, is_newtab:false, getHead: function(){ var head = document.getElementsByTagName('head')[0]; if (!head) { return document.body; } return head; }, addGlobalStyle: function(css) { var head = Transliterate.getHead(); var style = document.createElement('style'); style.type =

Cutting Edge: Live Data Binding in ASP.NET AJAX 4.0


Dino Esposito discusses various forms of client-side data binding as they are coming out in ASP.NET AJAX 4.0, focusing on some advanced features of data binding and observable objects.

Dino Esposito

MSDN Magazine December 2009

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