.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

how to bind xmldataprovider in MVVM?

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :WPF

Hello everyone,

I am new in MVVM. I am trying to binding XmlDataProvider with a treeview. I have a XmlProvider in my view,and i want to bind its source property with a another property which is situated in my viewmodel class ie Filepath property. For that i am writing this code

<XmlDataProvider x:Key="xmlDataProvider" Source="{Binding FilePath}" />

but it shows this error

A Binding can not be set on Source Property of type XmlDataProvider.Binding can only be set on  Dependency Property of Dependecy Object.

So how can I bind that Source of XmlDataProvider with the property which is in ViewModel?Is there any other solution for bind that property into View??

View Complete Post

More Related Resource Links

how to bind xmldataprovider in MVVM?


Hello everyone,

I am new in MVVM. I am trying to binding XmlDataProvider with a treeview. I have a XmlProvider in my view,and i want to bind its source property with a another property which is situated in my viewmodel class ie Filepath property. For that i am writing this code

<XmlDataProvider x:Key="xmlDataProvider" Source="{Binding FilePath}" />

but it shows this error

A Binding can not be set on Source property of type XmlDataProvider.Binding can only be set on  Dependency Property of Dependecy Object.

So how can I bind that Source of XmlDataProvider with the property which is in ViewModel?Is there any other solution for bind that property into View??

MVVM: How to bind a page in a tab control with a viewmodel?

We practise MVVM pattern.
We have a main window which contains tab controls. Each tabItem contains a page.
Since the main window needs to share some data with one of page, so our MainWindowViewModel creates the instance a RunconditionViewModel.
Then we need to set the instance of RunconditionViewModel to one of page's DataContent (page called ControlPage.xaml).
How do we achieve that? see the code below.

In HDMainWindow.xaml,
<TabControl x:Name="tabControlMain" DockPanel.Dock="Left" MinHeight="200"  SelectedIndex="0" TabStripPlacement="Left" >
<TabItem Header="Run" Name="TabItemControlPage"> <Frame Name="FrameControlPage" Source="Features\Basic Control\ControlPage.xaml"></Frame> <!--<Frame Source="Features\Basic Control\LoginPage.xaml"></Frame>--> </TabItem> in App.xaml.cs,

protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); InitializeComponent(); HDMainWindow hd = new HDMainWindow(); HDMainWindowViewModel hwd = new HDMainWindowViewModel(); hd.DataContext = hwd; //if (hd.TabItemControlPage != null) // hd.TabItemControlPage.DataContext = hwd.RunConditionsViewModel; if (hd.FrameControl

XmlDataProvider: Bind an XmlDocument with an XmlDataProvider


I am trying to use a XmlDocument (xmlDoc) with a XmlDataProvider to bind the XML document to a control.


However, I get the error message "The resource 'xmldata' could not be resolved." In code-behind this is how the XML document is loaded with a string at runtime: xmlDoc.LoadXml(e.data)



Any hints on how to solve the issue would be highly appreciated.


Thank you



<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" > <Window.Resources> <XmlDataProvider x:Key="xmlData" Document="xmlDoc" XPath="./ReportSnapshot" > </XmlDataProvider> </Window.Resources> <Grid Name="grid1" DataContext="xmldoc"> <TextBox Name="textbox1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Text="{Binding Source={StaticResource xmldata}, BindsDirectlyToSource=True, Path=Source, UpdateSourceTrigger=PropertyChanged}"> </TextBox> </Grid> </Window>

How to bind wpfdatagrid with collection of collection in MVVM pattern?


Hi everyone,

I am using MVVM pattern. I have some dynamic data and i want to bind it with datagrid. I converted my data in a collection which also contain anaother collection in following way.

First i create a class in my Model,which has some properties like this

namespace DummyDataGridBindingApplication.Models
   public class EntityAttribute
        public string AttributeName
        public string AttributeValue
        public string AttributDataType 

MVVM Bind View Details to Model Via ViewModel when a Button clicked.


I have model called Car with prperties name,model,type,year.

I have implemeted the Viewmodel with same properties with OnpropertyChangedEvent including model object type Property.

I have a view usercontrol where textboxes for name, model and for year a combobox.

Whenever i fill the view i want to save those details into model via view model

I have written ICommand  Save which calls SaveCarDetails defined in viewmodel,  which is bind to a button in view ,All other texboxes text is bind to the properties of viewmodel properties.

When i put break point at ICommand SaveCommand and SaveCarDetails Function i could see the values filled from view.

But when i bind these details to another user control where listbox is placed and its itemsource property is set to Car property nothing but model object defined in the viewmodel.

I couldn't see the values binding via viewmodel to model.

Where as if i bind to textboxes in the listview i could see the values because i it's a dependency property.

Can any one please tell me what is the wrong i am doing here.




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

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

How to bind TemplateField DropDownList with ArrayList?


Hi Expert!

  I'm trying gridview templateField DropDownList bind with arraylist. When i set bindsource i got this error. "//Error Object reference not set to an instance of an object."

My Sample .aspx

<asp:TemplateField HeaderText="Type">
                        <asp:DropDownList ID="_grvcboType" runat="server" Width="117px" DataTextField="Display" DataValueField="Value">
                        <asp:Label ID="Label7" runat="ser

how to bind Dropdownlist based on textbox values



I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this

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

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

Change data on gridview bind


Hi there,

Simple little problem. i have a gridview that shows products assigned to a customers job. They are displayed in exVAT prices. To make it easier i want to show the inc VAT prices. How can i add VAT to 1 column in this table?

Access and Bind data wihtout using Datasource Control


i want to bind my gridview with a dataset with concept of caching (to minimize the database server trips). plz give me a best example to get and bind data to gridview (command line) . grid paging is also enabled so example code should be capable to rebind data at Gridview page change.  

listview 3.5 bind dropdownlists edit item template VB.NET


I am trying to do this with many issues of data binding doubling the amount and not setting selectedValue on dropdownlist. I have read some posts and they help but I am missing a crucial piece. My problem is that my dropdownlist is doubling the amount of records for the dropdownlist. Instead of "YES;NO;SELECT A VALUE", I am getting "YES;NO;SELECT A VALUE;YES;NO;YES;NO". My database is correct with the UPDATE part but the rebind after update is failing horribly.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Session("ACTIVETAB").ToString() = Session("SUBCONTRACTSATABNO").ToString() Then
            End If
        End If
    End Sub

    Public Function loadlookups(ByVal id As String, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) As DataTable
        Select Case id
            Case "ddlCertReceived"
                dt = GetLookupTable("SubcontractsA", "Sub 1 Cert Received")
                Dim ddlCertReceived As DropDownList = _
                CType(e.Item.FindControl("ddlCertReceived"), DropDownList)
                ddlCertReceived.DataSource = dt
                ddlCertReceived.DataTextField = "lup_text"

bind values to dropdownlist using ASP.NET MVC



I'm using asp.net MVC 2.0, my controller coding is,

foreach(DataColumn dc in dtImport.Columns)


TempData["drpsku"] = dc.ColumnName.ToString();


i need to bind this value to the drpdown list in the aspx page.

<asp:DropDownList ID="DropDownList1" runat="server"></asp

Formview + EditItemTemplate + Bind + PageLoad + Prerender = Confused


I am working with a formview edititemtemplate.  Currently in my page load, i have some stuff that would show or hide certain panels based on dropdownlist values.  These dropdown values get binded during page load.  I need to be able to change the values/dropdowns, without rebinding the old data, and updating the visibility of the panels based on predefined rules.

I have experimented with putting my formview.databind() in page load if isnotpostback, in prerender, in prerender if isnotpostback.   I have tried my rules (ex if ddlState.selectedvalue = "DE" then pnlDelaware.visible = "true") in the page load, and the page render.   I'm just not sure how to get the stars aligned here.

The closest i have come is having the databind in the pageload if notispostback, and the rules in the prerender.   However I get an error "dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items.


Infopath form using Visual Studio - How to bind repeating table on submit button click ?


Hello friends,

   I have created infopath form using Visual Studio 2008

Form have 3 dropdowns and one repeating table which is bound by Datasource ( List from sharepoint ).

whenever i select appropritae values from drop down, Repeating table gets bound as datasource for dropdown and repeating table are same.

I have done conditional formating for repeating table using repeating table properties.


My Question:


Now i included one submit button and i want when i click submit button it will check DropDown Values and if appropriate record matching these values found it will fill repeating table

How i achive this ? as i dont find how to bind repeating table on submit button.

Please help if anyone have answer.


Thanks and Regards,


Kapil Bhosale.




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