Postupy: Použití vzoru seznam-podrobnosti s hierarchickými daty XMLHow to: Use the Master-Detail Pattern with Hierarchical XML Data

Tento příklad ukazuje, jak implementovat scénář seznam podrobnosti s XMLXML data.This example shows how to implement the master-detail scenario with XMLXML data.

PříkladExample

Tato ukázka je XMLXML data verzi příkladu popsané v použití vzoru seznam-podrobnosti s hierarchické Data.This example is the XMLXML data version of the example discussed in Use the Master-Detail Pattern with Hierarchical Data. V tomto příkladu se data ze souboru League.xml.In this example, the data is from the file League.xml. Poznámka: jak třetí ListBox řízení sleduje změny výběru za sekundu ListBox vazbou na jeho SelectedValue vlastnost.Note how the third ListBox control tracks selection changes in the second ListBox by binding to its SelectedValue property.

<Window x:Class="SDKSample.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Multiple ListBox Binding Sample"
  Width="400" Height="200"
  Background="Cornsilk">
    <Window.Resources>
      <XmlDataProvider x:Key="MyList" Source="Data\Leagues.xml"
                       XPath="Leagues/League"/>
      <DataTemplate x:Key="dataTemplate">
        <TextBlock Text="{Binding XPath=@name}" />
      </DataTemplate>
    </Window.Resources>

    <DockPanel DataContext="{Binding Source={StaticResource MyList}}">
      <StackPanel>
        <Label>My Soccer Leagues</Label>
        <ListBox ItemsSource="{Binding}"
                 ItemTemplate="{StaticResource dataTemplate}"
                 IsSynchronizedWithCurrentItem="true"/>
      </StackPanel>

      <StackPanel>
        <Label Content="{Binding XPath=@name}"/>
        <ListBox Name="divisionsListBox"
                 ItemsSource="{Binding XPath=Division}"
                 ItemTemplate="{StaticResource dataTemplate}"
                 IsSynchronizedWithCurrentItem="true"/>
      </StackPanel>

      <StackPanel>
        <Label Content="{Binding XPath=@name}"/>
        <ListBox DataContext="{Binding ElementName=divisionsListBox,
                                       Path=SelectedItem}"
                 ItemsSource="{Binding XPath=Team}"
                 ItemTemplate="{StaticResource dataTemplate}"/>
      </StackPanel>
    </DockPanel>
</Window>

Viz takéSee Also

HierarchicalDataTemplate
Témata s postupyHow-to Topics