简体   繁体   中英

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. In my WPF application in the xaml file I have added the following code:

<telerik:RadToggleButton CommandTarget="{Binding ElementName=doc}" Command="com:ToggleFontBoldCommand" Content="B"/>

doc is a richTextBox. com is the namespace of DevExpress commands' namespaces (xmlns:com="clr-namespace:DevExpress.XtraRichEdit.Commands; assembly=DevExpress.RichEdit.v16.1.Core") .
The point is that Visual Studio can not find the command. I believe that I am wrong with the CommandTarget but I do not know what is wrong.

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.

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:

<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".

Does this get you what you need?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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