XAML 错误:在类型“系统.Windows.控件.网格”上找不到模板属性“前景”

z5btuh9x  于 2022-12-07  发布在  Windows
关注(0)|答案(1)|浏览(122)

我正在尝试在选项卡控件的ControlTemplate触发器中添加属性“Foreground”:

<ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" />
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="False">
                                        <Setter TargetName="Panel" Property="Background" Value="Gray" />
                                        <Setter  Property="Foreground" TargetName="Panel" Value="White"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>

不幸的是,我得到这个错误:
错误在类型“系统.Windows.控件.网格”上找不到模板属性“前景.”
如何修复此错误?

iqjalb3h

iqjalb3h1#

我通过添加以下内容修复了该错误:

<Setter Property="TextElement.Foreground" TargetName="Panel" Value="White"></Setter>

所以完整的代码将是:

<ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="Panel" Property="Background" Value="LightSkyBlue" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="False">
                                <Setter TargetName="Panel" Property="Background" Value="Gray" />
 <Setter Property="TextElement.Foreground" TargetName="Panel" Value="White"/>

                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>

相关问题