J
Jules Winfield
Hello Friend,
I need to take a particular non-UI-related action when the user changes the
screen resolution. How can I detect when the screen resolution is changed by
the user?
Here's my first approach. I created an internal class called ScreenSize that
exposes a dependency property called ScreenWidth:
internal class ScreenSizeependencyObject{
public DependencyProperty
ScreenWidthProperty=DependencyProperty.Register("ScreenWidth",typeof(double),typeof(ScreenSize),new
PropertyMetadata(new PropertyChangedCallback(OnScreenWidthChanged)));
public double ScreenWidth{
get{return (double)this.GetValue(ScreenWidthProperty);}
set{this.SetValue(ScreenWidthProperty,value);}
}
private static void OnScreenWidthChanged(DependencyObject
d,DependencyPropertyChangedEventArgs e){
Debug.Print("Changed");
}
}
...and then I defined an instance of this class in the resources section of
the XAML file for my application:
<ResourceDictionary>
<aiacreenSize x:Key="ScreenSize" ScreenWidth="{DynamicResource {xtatic
SystemParameters.PrimaryScreenWidthKey}}"/>
</ResourceDictionary>
My expectation was that OnScreenWidthChanged() would be called whenever the
user manually changes the resolution. The reality, however, is that
OnScreenWidthChanged() is called once at startup and then never again --
even if the screen resolution is manually changed. Do you have an alternate
approach?
Thanks,
Jules
I need to take a particular non-UI-related action when the user changes the
screen resolution. How can I detect when the screen resolution is changed by
the user?
Here's my first approach. I created an internal class called ScreenSize that
exposes a dependency property called ScreenWidth:
internal class ScreenSizeependencyObject{
public DependencyProperty
ScreenWidthProperty=DependencyProperty.Register("ScreenWidth",typeof(double),typeof(ScreenSize),new
PropertyMetadata(new PropertyChangedCallback(OnScreenWidthChanged)));
public double ScreenWidth{
get{return (double)this.GetValue(ScreenWidthProperty);}
set{this.SetValue(ScreenWidthProperty,value);}
}
private static void OnScreenWidthChanged(DependencyObject
d,DependencyPropertyChangedEventArgs e){
Debug.Print("Changed");
}
}
...and then I defined an instance of this class in the resources section of
the XAML file for my application:
<ResourceDictionary>
<aiacreenSize x:Key="ScreenSize" ScreenWidth="{DynamicResource {xtatic
SystemParameters.PrimaryScreenWidthKey}}"/>
</ResourceDictionary>
My expectation was that OnScreenWidthChanged() would be called whenever the
user manually changes the resolution. The reality, however, is that
OnScreenWidthChanged() is called once at startup and then never again --
even if the screen resolution is manually changed. Do you have an alternate
approach?
Thanks,
Jules