【发布时间】:2016-01-18 10:48:34
【问题描述】:
我创建了一个自定义上下文菜单模板,如下所示:
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="Background" Value="{StaticResource menuBorderBrush}"/>
<Setter Property="Foreground" Value="{StaticResource menuForegroundBrush}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border" Background="{StaticResource menuBackgroundBrush}" BorderThickness="5" BorderBrush="{StaticResource menuBackgroundBrush}">
<StackPanel>
<TextBlock TextAlignment="Center" Padding="5,5,5,10">
You are not logged in.
</TextBlock>
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在我希望能够更改“您尚未登录”。以编程方式文本。我尝试从创建一个继承自 ContextMenu 的自定义控件类开始,并将 XAML 中的 x:Type 更改为此类,但随后属性(如背景、前景等)是未知的。
如果不从头实现新的 ContextMenu,我该如何做到这一点?
【问题讨论】: