[英]Set commands for a control in WPF
I am using DevExpress
for a WPF
application, I want to hit a toggle button and make the contents in a richTextBox
bold, the manual which is provided here suggests to use ToggleFontBoldCommand
as the command. 我正在将DevExpress
用于WPF
应用程序,我想单击一个切换按钮并使richTextBox
的内容richTextBox
粗体, 此处提供的手册建议使用ToggleFontBoldCommand
作为命令。 In my WPF application in the xaml
file I have added the following code: 在xaml
文件的WPF应用程序中,我添加了以下代码:
<telerik:RadToggleButton CommandTarget="{Binding ElementName=doc}" Command="com:ToggleFontBoldCommand" Content="B"/>
doc
is a richTextBox. doc
是richTextBox。 com
is the namespace of DevExpress commands' namespaces (xmlns:com="clr-namespace:DevExpress.XtraRichEdit.Commands; assembly=DevExpress.RichEdit.v16.1.Core")
. com
是DevExpress命令的命名空间的命名空间(xmlns:com="clr-namespace:DevExpress.XtraRichEdit.Commands; assembly=DevExpress.RichEdit.v16.1.Core")
。
The point is that Visual Studio
can not find the command. 关键是Visual Studio
无法找到该命令。 I believe that I am wrong with the CommandTarget
but I do not know what is wrong. 我相信CommandTarget
是错误的,但我不知CommandTarget
什么问题。
I'm just using the standard WPF ToggleButton
and TextBox
in this answer, but I believe the solution should also work with your telerik
and DevExpress
controls. 我在此答案中仅使用标准的WPF ToggleButton
和TextBox
,但我相信该解决方案也应与您的telerik
和DevExpress
控件一起使用。
If all you want is to make the text in the RichTextBox
bold when the RadToggleButton
has been clicked you should be able to side step the whole command thing and use something similar to the following: 如果只需要在单击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>
The style on the TextBox
changes the FontWeight
property from "Normal" to "Bold" when the ToggleButton
's IsChecked
property is "true". 当ToggleButton
的IsChecked
属性为“ true”时, TextBox
上的样式会将FontWeight
属性从“ Normal”更改为“ Bold”。
Does this get you what you need? 这能给您您所需要的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.