我已經將兩個列表框控件綁定到一個xml文件(即一個列表框綁定到xml,另一個綁定到第一個列表框)。列表框顯示xml文件中作爲綁定結果的節點值。可以創建添加,編輯和刪除操作並保留到源文件中,但目標不會更新,除非窗口關閉然後重新打開。第一個列表框的代碼如下:綁定目標未更新
<ListBox Name="listBox1" Width="224" Height="115" Margin="0,0,0,5"
IsSynchronizedWithCurrentItem="False" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Style="{StaticResource ListBoxStyle1}"
ItemsSource="{Binding Source={StaticResource RecipeList}, XPath=recipeType,
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="170"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Height="35" Background="#181818">
<TextBlock Background="Black" Margin="1" FontWeight="Bold"
Padding="7" Height="33" Width="184" Foreground="#D0D0D0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}">
<Binding XPath="@description" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和第二列表框:
<ListBox Name="listBox2" Width="218" Height="144" Margin="0,0,0,5"
IsSynchronizedWithCurrentItem="True" Style="{StaticResource ListBoxStyle1}"
ItemsSource="{Binding ElementName=listBox1, Path=SelectedItem, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Height="auto" Background="#181818">
<TextBlock Padding="7">
<StackPanel Background="Black" Margin="-5.5,-5.5,-6,-6.8">
<TextBlock Width="210" FontWeight="Bold" FontSize="12"
HorizontalAlignment="Left" Text="{Binding XPath=name}"
Background="Black" Foreground="#D0D0D0" Padding="0" Margin="5,0,0,3" />
<TextBlock Width="187" FontSize="11" HorizontalAlignment="Left"
Text="{Binding XPath=summary}" Background="Black" Foreground="Gray"
Margin="5,0,0,5" />
</StackPanel>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我的問題是如何更新目標或刷新/在這種情況下重新加載窗口。
感謝您的輸入。
按目標,你的意思是_listBox2_。 – publicgk 2011-03-26 13:35:48