我的xaml中有一个Image
。 Image
来自Converter
。当单击此图像时,它会更改绑定源的属性。
没有发生的是图像会立即改变它的来源,但如果我切换父级的DataContext
然后切换回更改的项目,它就会显示正常。
xaml:
<conv:BoolImageConverter x:Key="MarkiertImageConverter"/>
[...]
<Border x:Name="maBorder"
DataContext="{Binding SelectedItem, ElementName=myACB, NotifyOnSourceUpdated=True}">
<Grid>
[...]
<StackPanel Orientation="Horizontal"
VerticalAlignment="Bottom"
HorizontalAlignment="Stretch">
[...]
<Image x:Name="favImage"
[...]
Source="{Binding Markiert, NotifyOnSourceUpdated=True, Mode=OneWay, Converter={StaticResource MarkiertImageConverter}}"
MouseUp="favImage_MouseUp">
[...]
</Image>
</StackPanel>
</Grid>
</Border>
转换器:
public class BoolImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool m = (bool)value;
if (m)
{
return new BitmapImage(new Uri(@"/Resources/TrayPopup/bookmark_orange.png",UriKind.Relative));
}
return new BitmapImage(new Uri(@"/Resources/TrayPopup/bookmark_gray.png", UriKind.Relative));
}
[...]
}
背后的代码:
private void favImage_MouseUp(object sender, MouseButtonEventArgs e)
{
if ([...])
{
((Kollege)favImage.DataContext).Markiert = !((Kollege)favImage.DataContext).Markiert;
lbFavs.ItemsSource = favColleagueList;
}
}
为什么我的SourceUpdated
的{{1}}未被触发,我该如何解决?