tags:

views:

66

answers:

1

Hello, we're having this weird bug where if the application is opened and the user changes the windows font size here:

alt text

When the font size is changed to extra large, one of our controls DataContext is changed to null, and it's DataContextChanged event is called too. I set a breakpoint there and checked the callstack and this is part of wat I get:

Attune.exe!Invitrogen.TheGadget.ChartItemControl.chartControl_DataContextChanged(object sender = {Invitrogen.TheGadget.ChartItemControl}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 3903  C#
            PresentationFramework.dll!System.Windows.FrameworkElement.RaiseDependencyPropertyChanged(System.Windows.EventPrivateKey key, System.Windows.DependencyPropertyChangedEventArgs args) + 0x5c bytes   
            PresentationFramework.dll!System.Windows.FrameworkElement.OnDataContextChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x66 bytes 
            WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4a bytes 
            PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes   
            WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x2c bytes   
            WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {DataContext}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, System.Windows.OperationType operationType) + 0x515 bytes   
            WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, System.Windows.OperationType operationType, bool isInternal) + 0x1eb bytes   
            WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x2e bytes   
            PresentationFramework.dll!System.Windows.FrameworkElement.DataContext.set(object value) + 0x24 bytes    

Attune.exe!Invitrogen.TheGadget.ChartItemControl.OnRemoved() Line 1447 + 0xa bytes C#

Not really sure what is going on, nor why or what changes the DataContext of the control. Any help would be greatly appreciated.

Thanks!

+2  A: 

I'm assuming ChartItemControl is a System.Windows.Controls.Control or UserControl. A Control's *Unloaded* event will be fired when modifying the windows theme, color scheme, or font size. If you are cleaning up resources by resetting DataContext when handling the Unloaded event, you will need to reset your DataContext when the control is loaded again or in OnApplyTemplate.

Ed Noepel
Wow, great answer. I had no idea this happened. Thanks!
Carlo
Btw, do you know what other events happen when the font is changed? I need an event that happens BEFORE Unloaded (OnApplyTemplate works), and one that happens AFTER, so I can set true to a flag in OnApplyTemplate, and set it to false in the event that happens after. Thanks!
Carlo
Or if is there a way for the control to completely ignore the Windows change?
Carlo
I do not know of any events that would happen "after" a control is Unloaded. I am unsure what you wish to accomplish with the flag. It is impractical to ignore the change, since the default templates for primative WPF controls adapt to the selected theme. This design allows WPF applications to maintain a consistant appearance with Win32/WinForms applications, even though Win32 messages are not used to draw the UI components.I recommend designing your controls such that the same instance may be unloaded and reloaded without losing state.
Ed Noepel