我收到了这个错误,无论我谷歌多少,我都不知道如何解决它!
这是我的Theme.xaml
中定义的样式 <Style x:Key="RightClickCopyPasteLabel" TargetType="Label">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Label">
<ContextMenu>
<ContextMenu Opened="OnMenuOpened">
<MenuItem x:Name="CopyMenuItem" Click="OnCopyEvent" InputGestureText="Ctrl+C" Header="Copy" IsEnabled="{Binding CanExecuteCopy}">
</MenuItem>
<MenuItem x:Name="PasteMenuItem" Click="OnPasteEvent" InputGestureText="Ctrl+P" Header="Paste" IsEnabled="{Binding CanExecutePaste}">
</MenuItem>
</ContextMenu>
</ContextMenu>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这是我的控制。真的很少说。我认为它应该有效。我想为右键单击上下文菜单创建一个模板,我可以将其应用于标签。我不确定我哪里出错了?
<UserControl x:Class="DataForgeEditor.Controls.Expander"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/DataForgeTheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Expander Name="ExpanderControl" Margin="5,5,5,5">
<Expander.Header>
<Label Name="ExpanderLabel" Style="{StaticResource RightClickCopyPasteLabel}" />
</Expander.Header>
</Expander>
修改
我刚试过这个非常基本的风格..这甚至不起作用!
<Style x:Key="TestLabel" TargetType="Label">
<Setter Property="Template">
<Setter.Value>
<Border Background="AntiqueWhite"></Border>
</Setter.Value>
</Setter>
</Style>