XAML syntax error is blocking designer but compiling fine

后端 未结 2 1809
暗喜
暗喜 2020-12-19 01:31

I\'ve run into a rather bizarre thing happening, I have a DataGrid defined in a WPF XMAL page that has the following declared:



        
相关标签:
2条回答
  • 2020-12-19 02:08

    If you don't want to use code behind then an alternative to InactiveSelectionHighlightBrushKey is ControlBrushKey. The following worked for me:

    <Style x:Key="ReadOnlyDataGrid" TargetType="{x:Type DataGrid}">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGreen"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightGreen"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black"/>
        </Style.Resources>
    </Style>
    
    0 讨论(0)
  • 2020-12-19 02:12

    Visual Studio builds an assembly, even if its target set to .NET FW 4.0 and you use InactiveSelectionHighlightBrushKey in XAML-code. This assembly will be correctly performed in a system with .NET FW 4.5. But if the system has only .NET FW 4.0, an exception will be thrown when the system create User control with InactiveSelectionHighlightBrushKey.

    So you cannot use the InactiveSelectionHighlightBrushKey in assemblies with target set to FW 4.0, because they will not work in a system with only .NET FW 4.0.

    To support both FW 4.0 and FW 4.5 you can set a color of the selected row in handlers of LostFocus/LostKeyboardFocus/GotFocus events. See the example code https://stackoverflow.com/a/8095932/1815957

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