该按钮显示为灰色的原因是因为您已告诉它使用内置的剪切命令。This means that the Button
will be automatically disabled when there is nothing to cut and enabled when something that can be cut is selected (such as text).
要验证这一点,您可以做两件事;删除 cut 命令并查看该按钮现在已启用:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ToolBarTray Margin="0,21,0,0" Width="Auto" Height="38" VerticalAlignment="Top">
<ToolBar Height="38">
<Button IsEnabled="True">
Click
</Button>
</ToolBar>
</ToolBarTray>
</Grid>
</Window>
或者添加一个富文本框控件,当你选择一些文本时,看看按钮是启用的:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ToolBarTray Width="Auto" VerticalAlignment="Top">
<ToolBar Height="38" >
<Button IsEnabled="True" Command="Cut">
Click
</Button>
</ToolBar>
</ToolBarTray>
<RichTextBox Grid.Row="1"/>
</Grid>
</Window>