繁体   English   中英

在WPF中设置控件的命令

[英]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 ToggleButtonTextBox ,但我相信该解决方案也应与您的telerikDevExpress控件一起使用。

如果只需要在单击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>

ToggleButtonIsChecked属性为“ true”时, TextBox上的样式会将FontWeight属性从“ Normal”更改为“ Bold”。

这能给您您所需要的吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM