[英]Set commands for a control in WPF
我正在将DevExpress
用于WPF
应用程序,我想单击一个切换按钮并使richTextBox
的内容richTextBox
粗体, 此处提供的手册建议使用ToggleFontBoldCommand
作为命令。 在xaml
文件的WPF应用程序中,我添加了以下代码:
<telerik:RadToggleButton CommandTarget="{Binding ElementName=doc}" Command="com:ToggleFontBoldCommand" Content="B"/>
doc
是richTextBox。 com
是DevExpress命令的命名空间的命名空间(xmlns:com="clr-namespace:DevExpress.XtraRichEdit.Commands; assembly=DevExpress.RichEdit.v16.1.Core")
。
关键是Visual Studio
无法找到该命令。 我相信CommandTarget
是错误的,但我不知CommandTarget
什么问题。
我在此答案中仅使用标准的WPF ToggleButton
和TextBox
,但我相信该解决方案也应与您的telerik
和DevExpress
控件一起使用。
如果只需要在单击RadToggleButton
时使RichTextBox
的文本RadToggleButton
粗体 ,则您应该可以使整个命令RadToggleButton
并使用类似于以下内容的命令:
<ToggleButton x:Name="BoldToggle" />
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="FontWeight" Value="Normal"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=BoldToggle}" Value="true">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
当ToggleButton
的IsChecked
属性为“ true”时, TextBox
上的样式会将FontWeight
属性从“ Normal”更改为“ Bold”。
这能给您您所需要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.