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.
here is my XAML code,
<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.
<Button Name="grdBtnAdd" IsEnabled="{Binding IsNewRecordsAvailable}" Cursor="Hand" Click="Button_Click_1" Width="20" Height="20">
...
</Button>
Set the viewModel as the views' dataContext:
Sub New()
Me.Datacontext = new viewModel
End Sub
The viewModel will implement INotifyPropertyChanged, and the property will look like this:
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.
Here are some more examples:
http://msdn.microsoft.com/en-us/library/ms229614.aspx http://www.codeproject.com/KB/cs/BindBetterINotifyProperty.aspx
精彩评论