'{DependencyProperty.UnsetValue}' is not a valid value for the "FocusVisualStyle" property

I have a strange error that I am trying to debug without luck.

I have a subclassed hwndhost showing some content, I have the following function in this class to set full screen mode:

private void SetFullScreen(bool enable) { if (enable) { fs = new Window(); fs.ResizeMode = ResizeMode.NoResize; fs.WindowState = System.Windows.WindowState.Maximized; fs.WindowStyle = System.Windows.WindowStyle.None; fs.Topmost = true; fs.PreviewKeyDown += delegate(object sender, KeyEventArgs e) { if (e.Key==Key.Escape) FullScreen = false; }; fs.Show(); } else { fs.Close(); fs = null; } } 

This works fine in my prototype WPF application, but when I use this code in my main application, I get this error when I close the window (escape key) and when fs.close() called:

'{DependencyProperty.UnsetValue}' is not a valid value for property 'FocusVisualStyle'.

It is strange that this happens after about 1500 m. AFTER the window is closed. I tried setting FocusVisualStyle on fs to null, but it looks like something else. Feeling tired is an attempt to focus another element in my application that does not have this property, but in fact I have no idea!

Thanks!

Change The problem was setting FocusVisualStyle on my fullscreen button. I installed {x: Null} and the problem disappeared.

+6
wpf dependency-properties
source share
2 answers

I assume that the control that receives focus when closing the specified window has a custom style that does not include FocusVisualStyle.

to help you further, you should explain a little more: what happens (or should happen) when you close this window?

What type of management should get focus?

+7
source share

This can happen when the style points to a non-existent StaticResource.

This Xaml failed:

 <Grid.Resources> <Style TargetType="{x:Type TextBox}"> <Setter Property="Height" Value="{StaticResource StandardControlHeight}"/> <Setter Property="VerticalContentAlignment" Value="Center"/> </Style> </Grid.Resources> 

The error was:

System.InvalidOperationException: '' {DependencyProperty.UnsetValue} 'is not a valid value for the' Height 'property.'

When I added the missing StaticResource, the problem disappeared.

0
source share

All Articles