سؤال

I want make a system of change language witch change XML File.

I have a XML file, this struct is this:

<List>
    <File>Arquivo</File>
    <Edit>Editar</Edit>
    <View>Visual</View>
</List>

In my WPF:

<TextBlock Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="File" VerticalAlignment="Top" Text="File">
<TextBlock Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Edit" VerticalAlignment="Top" Text="Edit">
<TextBlock Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="View" VerticalAlignment="Top" Text="View">

So, How to binding this TextBlock's text with XML file values?

هل كانت مفيدة؟

المحلول

First you'll need to create XmlDataProvider, something like this:

<Window.Resources>
  <XmlDataProvider x:Key="InventoryData">
      <x:XData>
          <List xmlns="">
              <File>Arquivo</File>
              <Edit>Editar</Edit>
              <View>Visual</View>
          </List>
      </x:XData>
  </XmlDataProvider>
</Window.Resources>

You can also load it from extenral XML file by specifing XmlDataProvider.Source. When you have your source then you bind it by specifying Binding.Source as InventoryData and Binding.XPath to node that interests you, something like this:

<StackPanel>
  <TextBlock Text="{Binding Source={StaticResource InventoryData}, XPath=List/File}"/>
  <TextBlock Text="{Binding Source={StaticResource InventoryData}, XPath=List/Edit}"/>
  <TextBlock Text="{Binding Source={StaticResource InventoryData}, XPath=List/View}"/>
</StackPanel>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top