我有以下ViewModel对象:
public class ImageContent : DependencyObject
{
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(ImageSource), typeof(ImageContent), new PropertyMetadata(null, ImagePropertyChanged));
private static void ImagePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
public ImageSource Image
{
get { return (ImageSource)GetValue(ImageProperty); }
set { SetValue(ImageProperty, value); }
}
}
在XAML中,我将它用作我按钮的内容,如下所示:
<Button Style="{StaticResource CallOptionButtonStyle}">
<viewModel:ImageContent Image="{ThemeResource imgKeypad}"/>
</Button>
我注意到当我在Windows Phone 8.1上更改主题时,按钮上的图像不会更改。 此外,ImagePropertyChanged也未被触发。
但是,如果我从(例如)Button继承一个对象,则触发相同的属性并更改主题,而不是触发ImagePropertyChanged。
有没有解释? 据我所知,拥有ThemeResource对象应该是VisualTree的一部分,以获取有关ThemeResource的通知?
有任何变通方法吗?如何在自定义ViewModel中接收从DependencyObject继承的通知?