[英]WPF gridview button column disable only the button
I need to disable gridview button only when data bind or button click because I need to disable that button for existing records only and when user add new record need to active my grid button.我需要仅在数据绑定或按钮单击时禁用 gridview 按钮,因为我需要仅对现有记录禁用该按钮,并且当用户添加新记录需要激活我的网格按钮时。
here is my XAML code,这是我的 XAML 代码,
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="grdBtnAdd" Cursor="Hand" Click="Button_Click_1" Width="20" Height="20" >
<Button.Template>
<ControlTemplate>
<Border Style="{StaticResource borstyle}" BorderBrush="#282828" BorderThickness=".5" CornerRadius="3" Name="bor" >
<Image Width="20" Height="18" Source="/Images\plus1.png"></Image>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
please help me.请帮我。 I found how to disable button after click grid button.我找到了单击网格按钮后如何禁用按钮。 I need a way to disable grid buttons.我需要一种禁用网格按钮的方法。
If i understood the issue correctly than the following should work:如果我正确理解了这个问题,那么以下应该可以工作:
Bind the button IsEnabled property to a property in the viewModel.将按钮 IsEnabled 属性绑定到 viewModel 中的属性。
<Button Name="grdBtnAdd" IsEnabled="{Binding IsNewRecordsAvailable}" Cursor="Hand" Click="Button_Click_1" Width="20" Height="20">
...
</Button>
Set the viewModel as the views' dataContext:将 viewModel 设置为视图的 dataContext:
Sub New()
Me.Datacontext = new viewModel
End Sub
The viewModel will implement INotifyPropertyChanged, and the property will look like this: viewModel 将实现 INotifyPropertyChanged,属性将如下所示:
Private m_isNewRecordsAvailable As Boolean
Public Property IsNewRecordsAvailable() As Boolean
Get
Return m_isNewRecordsAvailable
End Get
Set(ByVal value As Boolean)
m_isNewRecordsAvailable = value
NotifyPropertyChanged("IsNewRecordsAvailable")
End Set
End Property
Now when you want to enable or disable the button, just set IsNewRecordsAvailable to true or false.现在,当您想要启用或禁用按钮时,只需将 IsNewRecordsAvailable 设置为 true 或 false。
Here are some more examples:以下是更多示例:
http://msdn.microsoft.com/en-us/library/ms229614.aspx http://www.codeproject.com/KB/cs/BindBetterINotifyProperty.aspx http://msdn.microsoft.com/en-us/library/ms229614.aspx http://www.codeproject.com/KB/cs/BindBetterINotifyProperty.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.