WPF工具栏按钮不';我似乎没有反应
我有以下代码:WPF工具栏按钮不';我似乎没有反应,wpf,button,toolbar,Wpf,Button,Toolbar,我有以下代码: <ToolBarTray Margin="0,21,0,0" Width="Auto" Height="38" VerticalAlignment="Top"> <ToolBar Height="38"> <Button Style="{StaticResource ResourceKey=btnStyle}" Command="Cut" IsEnabled="True">
<ToolBarTray Margin="0,21,0,0" Width="Auto" Height="38" VerticalAlignment="Top">
<ToolBar Height="38">
<Button Style="{StaticResource ResourceKey=btnStyle}" Command="Cut" IsEnabled="True">
<Image Source="images/teren.png" ToolTip="Test" />
</Button>
</Toolbar>
</ToolBarTray>
目前讨论的样式只会改变高度和宽度。每个元素都是相应地绘制的,但是按钮似乎不起作用,因为无论出于何种目的,它看起来都像一个图像,而不是其他任何东西。工具提示将不会显示,它没有悬停动画,并且无法真正按下
我是WPF的新手,所以我猜我错过了一些重要的事情
问题不在图像中。如果我删除该行,它仍然不会像按钮一样工作。按钮变灰的原因是您告诉它使用内置的剪切命令。这意味着当没有要剪切的内容时,
按钮将自动禁用,而当选择了可以剪切的内容(如文本)时,按钮将启用
要验证这一点,您可以做两件事;删除“剪切”命令并查看按钮是否已启用:
<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>
点击
选中以创建imagebutton用户控件以接受具有按钮应有效果的图像。。