1

I have the following ViewModel object:

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); }
    }
}

In XAML I will use it as a content to my button like this:

        <Button Style="{StaticResource CallOptionButtonStyle}">
            <viewModel:ImageContent Image="{ThemeResource imgKeypad}"/>
        </Button>

I noticed that when I change theme on Windows Phone 8.1 the image on a button is not changed. Also ImagePropertyChanged is not fired.

But if I inherit an object from (for example) Button, make the same property and change theme than ImagePropertyChanged is fired.

Are there any explanations to it? As far as i see owning ThemeResource object should be part of VisualTree to get notification about ThemeResource?

Are there any workarounds? How can I receive notification in my custom ViewModel which is inherited from DependencyObject ?

norekhov
  • 3,915
  • 25
  • 45

0 Answers0