Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Dynamic XML Data Binding

 
 
Old 04-24-2006   #1 (permalink)
Ben


 
 

Dynamic XML Data Binding

I would like to have a dynamic data binding in my application: if I
press a button, I bind a text box to an XML Data source, and if I press
on another one, I bind it to another XML file... In fact, something
like this function on my Button MouseClickHandler:

private void loadXML1(object sender, System.Windows.RoutedEventArgs e)
{

Binding bind = new Binding();

bind.Source = @"c:\xml\xml1.xml";
bind.XPath="/User/Name";
bind.Mode=System.Windows.Data.BindingMode.Default ;

this.nameTextBox.SetBinding(TextBlock.TextProperty,bind);


}

And another one with the @"c:\xml\xml2.xml" path on my other Button.

It's not working... what should I change?


My System SpecsSystem Spec
Old 04-24-2006   #2 (permalink)
Drew Marsh


 
 

Re: Dynamic XML Data Binding

ben wrote:

> I would like to have a dynamic data binding in my application: if I
> press a button, I bind a text box to an XML Data source, and if I
> press on another one, I bind it to another XML file... In fact,
> something like this function on my Button MouseClickHandler:
>
> ... code snipped for brevity ...
>
> And another one with the @"c:\xml\xml2.xml" path on my other Button.
>
> It's not working... what should I change?


You need to define an XmlDataProvider[1], specify that instance as the source
of your bindings and then you can change it's Source property in your buttons
and anything bound to it should be updated automatically as the new document
is loaded.

HTH,
Drew

[1] http://windowssdk.msdn.microsoft.com...taProvider.asp

___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 04-25-2006   #3 (permalink)
Ben


 
 

Re: Dynamic XML Data Binding

Thanks for the answer, but I really don't know a lot about C# and XAML
and have problems implementing it:
My XmlDataProvider is: <XmlDataProvider x:Key="XMLdb"
d:IsDataSource="True" Source="D:\db_A.xml"/>

In the code behind my button, I don't know how to do in order to change
the source of this XmlDataProvider.

--
Benjamin

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Problem in dynamic WPF ListView binding .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46