如何在用户控件上实现ApplicationCommands.Cut等启用/禁用行为

时间:2015-01-23 20:55:14

标签: wpf focus controls toolbar behavior

我创建了一个用户控件,它是一个工具栏,上面有几个按钮。工具栏包含一些常规功能,如复制,粘贴,撤消,重做等。这些按钮使用内置命令,如此。

<UserControl x:Class="Foundation.FundRaising.DataRequest.Windows.Controls.TextEditorToolBar"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
         mc:Ignorable="d" 
         d:DesignHeight="34" d:DesignWidth="550">
<Grid>
    <telerik:RadToolBar>
        <telerik:RadToolBar.Resources>
            <Style TargetType="StackPanel">
                <Setter Property="Orientation" Value="Horizontal"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            <Style TargetType="Image">
                <Setter Property="Width" Value="20"/>
                <Setter Property="Height" Value="20"/>
            </Style>
        </telerik:RadToolBar.Resources>
        <telerik:RadButton Command="Cut">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/cut20.png" ToolTip="Cut"/>
                <Label Content="Cut"/>
            </StackPanel>
        </telerik:RadButton>
        <telerik:RadButton Command="Copy">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/copy20.png" ToolTip="Copy"/>
                <Label Content="Copy"/>
            </StackPanel>
        </telerik:RadButton>
        <telerik:RadButton Command="Paste">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/paste20.png" ToolTip="Paste"/>
                <Label Content="Paste"/>
            </StackPanel>
        </telerik:RadButton>
        <telerik:RadButton Command="Delete">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/delete24.png" ToolTip="Delete"/>
                <Label Content="Delete"/>
            </StackPanel>
        </telerik:RadButton>

        <telerik:RadToolBarSeparator/>

        <telerik:RadButton Command="Undo">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/undo20.png" ToolTip="Undo"/>
                <Label Content="Undo"/>
            </StackPanel>
        </telerik:RadButton>
        <telerik:RadButton Command="Redo">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/redo20.png" ToolTip="Redo"/>
                <Label Content="Redo"/>
            </StackPanel>
        </telerik:RadButton>
        <telerik:RadButton x:Name="radButtonSpellCheck" Click="RadButtonSpellCheckClick">
            <StackPanel>
                <Image Source="/Foundation.FundRaising.DataRequest.Windows;component/Resources/spell_check24.png" ToolTip="Spell Check"/>
                <Label Content="Spell Check"/>
            </StackPanel>
        </telerik:RadButton>            
    </telerik:RadToolBar>
</Grid>

我已添加了#34;拼写检查&#34;使用Telerik RadSpellChecker控件的按钮,就像这样。

    private void RadButtonSpellCheckClick(object sender, RoutedEventArgs e)
    {
        try
        {
            IInputElement control = Keyboard.FocusedElement;
            RadSpellChecker.Check((Control)control, SpellCheckingMode.AllAtOnce);
        }
        catch (NotImplementedException)
        {
            RadWindow.Alert("You have selected a control that does not support the spell check feature.");
        }
    }

所有这一切都很好,但我想做的是进行&#34;拼写检查&#34;按钮启用/禁用当控件像内置命令一样聚焦时,无需捕获异常并向用户显示警报。基本上,确定关注控件是否可以接受&#34;功能&#34;。

0 个答案:

没有答案