Bound target not updating
I have bound two listbox controls to an xml file (i.e one list box bound to the xml and the other bound to the first listbox). The listboxes display node values within the xml file as a result of the binding. Add, Edit and Delete operations can be made and do persist to the source file, however the target doesn't get updated unless the window is closed and then reopened. The code for the first list box is as follows:
<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>
and for the second 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>
My question is how to update the target or refresh/reload the window in this case.
Thanks for your input.
In ListBox2, you are binding to a specific item (listBox1.SelectedItem) so IsSynchronizedWithCurrentItem should be false. IsSynchronizedWithCurrentItem is for when you are binding to a collection but want only the selected item.
精彩评论