【发布时间】:2016-10-02 13:01:28
【问题描述】:
下面xaml代码中有一个按钮:
<Button Grid.Row="1" x:Name="First" Content="First" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="40,91,0,67" />
在窗口的构造函数中,我已将ApplicationCommands.Copy 分配给按钮。
public MainWindow()
{
InitializeComponent();
this.doc.Unit = DevExpress.Office.DocumentUnit.Point;
this.First.Command = ApplicationCommands.Copy;
First.CommandTarget = this.doc;
}
上面代码中的this.doc是一个典型的richTextBox。
问题是按钮总是被禁用。为什么?
整个xaml代码如下:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:com="clr-namespace:DevExpress.XtraRichEdit.Commands;assembly=DevExpress.RichEdit.v16.1.Core"
xmlns:dxre="http://schemas.devexpress.com/winfx/2008/xaml/richedit" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="700" Width="1000" x:Name="wnd">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="163*" />
<RowDefinition Height="60*" />
</Grid.RowDefinitions>
<dxre:RichEditControl x:Name="doc" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,23" Unit="Point" ActiveViewType="PrintLayout"/>
<!--<telerik:RadToggleButton
Content="B" HorizontalAlignment="Left" Height="Auto" IsThreeState="False" IsChecked="False" Margin="10,32,0,0" Grid.Row="1" VerticalAlignment="Top" Width="26"/>-->
<Button Grid.Row="1" x:Name="First" Content="First" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="40,91,0,67" />
</Grid></Window>
【问题讨论】:
-
你能显示所有相关的 XAML 吗?可能是您的按钮位于因某种原因而被禁用的容器中。
-
@rory.ap 实际上我的 xaml 代码中只有那个按钮
-
所以当您说“禁用”时,您的意思是“变灰”吗?或者是什么?即使您只有按钮,它也至少在一个 Window 控件中。
-
实际上它是灰色的并且不工作,它是可见的。在 winForms 中它被称为禁用状态。