XMLDataProvider binding  
Author Message
MattyBoy4444





PostPosted: Windows Presentation Foundation (WPF), XMLDataProvider binding Top

I can bind a TextBox Text property to a XML file using XMLDataProvider.

Question: How do you get TwoWay binding with an XML file Or, how would I resave the file



Visual Studio 200827  
 
 
Zhou Yong





PostPosted: Windows Presentation Foundation (WPF), XMLDataProvider binding Top

XmlDataProvider only supports one way data binding, if you wanna enable two way data binding for xml, you should write your own data source entity and data source collection, and those entities and collections presumably should implement WPF's observer pattern.

Sheva


 
 
Douglas Stockwell





PostPosted: Windows Presentation Foundation (WPF), XMLDataProvider binding Top

MattyBoy: If you just place an ordinary XmlDocument in the XmlDataProvider, you can just hold the reference and save it later on.

Sheva: You might be surprised:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Page.Resources>
    <XmlDataProvider x:Key="a">
      <x:XData>
        <item xmlns="">hello</item>
      </x:XData>
    </XmlDataProvider>
  </Page.Resources>
  <StackPanel>
     <TextBox Text="{Binding Source={StaticResource a}, XPath=/item/text(), UpdateSourceTrigger=PropertyChanged}" />
     <TextBox Text="{Binding Source={StaticResource a}, XPath=/item/text(), UpdateSourceTrigger=PropertyChanged}" />
  </StackPanel>
</Page>


 
 
Zhou Yong





PostPosted: Windows Presentation Foundation (WPF), XMLDataProvider binding Top

Yep, you are right Doug, this teaches me one lesson: try it before barking up the tree

Sheva


 
 
lilR





PostPosted: Windows Presentation Foundation (WPF), XMLDataProvider binding Top

Hi there,

the the Example of Douglas is nice concerning a two way binding, but it doesn`t solve the saving problem. Once the Application is closed the old data is back.

I have a workaround for this by using a DataSets Read/WriteXml methods because two way binding works well in memory.

Do you guys have another way to bind in two way mode to a xml file

CU

lilOne