![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | WPF: Detect Screen Resolution Change (without constantly polling SystemParameters)? 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Detect Screen Resolution Change (without constantly polling SystemParameters)? Hi Jules, Based on my understanding,you'd like to get notified in your WPF application when the user changes the screen resolution. If I'm off base, please feel free to let me know. In your scenario, you use an instance of the ScreenSize class in the resource dictionary within a window and bind the SystemParameters.PrimaryScreenWidthKey to the instance's ScreenWidth dependency property. When the application starts up, this ScreenWidth property is assigned. However, the ScreenSize instance used in the resource section doesn't have a resource tree, so when the system parameter changes, the ScreenWidth property won't be updated immediately. If what you really want is only to get notified in the application when the screen resolution is changed, I suggest that you subscribe and handle the DisplaySettingsChanged event of SystemEvents in the window. For example: public partial class Window1 : Window { public Window1() { InitializeComponent(); SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged); } void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e) { Debug.WriteLine("display settings changed"); } } Hope this hleps. If you have any question, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...#notifications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Detect Screen Resolution Change (without constantly polling SystemParameters)? > If what you really want is only to get notified in the application when Quote: > the screen resolution is changed, I suggest that you subscribe and handle > the DisplaySettingsChanged event of SystemEvents in the window. > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Unable to change Screen Resolution | Vista hardware & devices | |||
| How do I change the screen resolution on my computer? | Vista hardware & devices | |||
| Cannot change screen resolution | Vista installation & setup | |||
| Change screen resolution for different users | Vista account administration | |||
| Message asking me to change screen resolution | Vista General | |||