我有一些數據保存在xml文件中。 這些將顯示在列表框中。 現在,當我更改列表框Selectedindex時,我想根據selectedindex更新textblock中的其他信息。將textblock綁定到純xaml中的當前列表框項目
有沒有辦法在純xaml中做到這一點? 如果不是,我將如何將Textblock綁定到列表框中的selecteditem?
編輯: 我如何瀏覽數據而不使用列表框?我的意思是使用一個按鈕移動到下一個項目和其他按鈕向後移動..!
任何幫助非常感謝..
<Window x:Class="WpfSingleInstance.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Cornsilk">
<StackPanel.Resources>
<XmlDataProvider x:Key="InventoryData" XPath="Inventory/Books">
<x:XData>
<Inventory xmlns="">
<Books>
<Book ISBN="0-7356-0562-9" Stock="in" Number="9">
<Title>XML in Action</Title>
<Summary>XML Web Technology</Summary>
</Book>
<Book ISBN="0-7356-1370-2" Stock="in" Number="8">
<Title>Programming Microsoft Windows With C#</Title>
<Summary>C# Programming using the .NET Framework</Summary>
</Book>
<Book ISBN="0-7356-1288-9" Stock="out" Number="7">
<Title>Inside C#</Title>
<Summary>C# Language Programming</Summary>
</Book>
</Books>
</Inventory>
</x:XData>
</XmlDataProvider>
</StackPanel.Resources>
<TextBlock FontSize="18" FontWeight="Bold" Margin="10"
HorizontalAlignment="Center">XML Data Source Sample</TextBlock>
<ListBox
Width="265" Height="98" x:Name="lbox" Background="Honeydew" IsSynchronizedWithCurrentItem="True">
<ListBox.ItemsSource>
<Binding Source="{StaticResource InventoryData}"
XPath="*[@Stock='out'] | *[@Number>=8 or @Number=3]"/>
</ListBox.ItemsSource>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock FontSize="12" Foreground="Red">
<TextBlock.Text>
<Binding XPath="Title"/>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel DataContext="{StaticResource InventoryData}">
<TextBlock Text="{Binding XPath=Book/Title}"/>
<TextBox Margin="5,31,98,10" x:Name="textBoxMainDetail" Text="{Binding XPath=Book/Summary}" />
</StackPanel>
</StackPanel>
</Grid>
您好,感謝的作品......可我還添加了一個按鈕,通過數據導航,而不使用列表框?我的意思是,如果我刪除列表框,我將如何瀏覽XML數據?moveforward(),moveback()等.. – lebhero 2012-02-02 12:43:32
我猜在沒有列表框的情況下瀏覽數據可能會更好地在代碼後面完成。有些東西應該跟蹤當前/選定的項目。 – Clemens 2012-02-02 13:11:20
任何代碼或例子?? Beispiele :) – lebhero 2012-02-02 13:14:34