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

后端 未结 4 827
广开言路
广开言路 2021-01-11 09:36

I have a weird error I\'m trying to debug with no luck.

I have subclassed hwndhost showing some content, I have the following function in that class to set to fullsc

相关标签:
4条回答
  • 2021-01-11 09:44

    In case you got here by Googling the question title: Another way to cause this exception is to use a Trigger, but forget to set the Value.

    Example:

    <ControlTemplate.Triggers>
      <Trigger Property="IsEnabled">
        <Setter Property="Background" Value="Gray" />
      </Trigger>
    </ControlTemplate.Triggers>
    

    This causes a XamlParseException where the inner exception reads:

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

    Correction:

    <ControlTemplate.Triggers>
      <Trigger Property="IsEnabled" Value="False">
        <Setter Property="Background" Value="Gray" />
      </Trigger>
    </ControlTemplate.Triggers>
    
    0 讨论(0)
  • 2021-01-11 10:05

    my guess is that the control that gets the focus when you close the mentioned window has a custom style set by you that does not include any FocusVisualStyle.

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

    what control type is supposed to get the focus?

    0 讨论(0)
  • 2021-01-11 10:05

    Yet another way to cause mentioned exception is when you declare StaticResource after using it, for example in style declaration.

    WRONG

    <Style TargetType="Label">
        <Setter Property="Foreground" Value="{StaticResource BlueAccent}"/>
    </Style>
    
    <SolidColorBrush x:Key="BlueAccent" Color="#22afed"/>
    

    CORRECT

    <SolidColorBrush x:Key="BlueAccent" Color="#22afed"/>
    
    <Style TargetType="Label">
        <Setter Property="Foreground" Value="{StaticResource BlueAccent}"/>
    </Style>
    
    0 讨论(0)
  • 2021-01-11 10:07

    This can happen when a Style is pointing to a StaticResource that does NOT exist.

    This xaml was failing:

    <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 property 'Height'.'

    When I added the missing StaticResource, the problem went away.

    0 讨论(0)
提交回复
热议问题