Question

I am developing a Silverlight web part for Sharepoint 2010. I have a button in a datagrid as follows

<sdk:DataGridTemplateColumn Width="80" >
   <sdk:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <Button x:Name="MarkBilledButton" Content="Mark Billed"  VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Click="MarkBilledButton_Click" />
      </DataTemplate>
   </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

private void MarkBilledButton_Click(object sender, RoutedEventArgs e)
{
   Button btn = sender as Button;
   //string buttonContent = btn.Content.ToString();
   MedwaiverTimeLog timeLogObj = btn.DataContext as MedwaiverTimeLog;
   MedwaiverViewModel MedwaiverViewModelObj = new MedwaiverViewModel();
   MedwaiverViewModelObj.ChangeBillingStatus(timeLogObj.ListItemId, "Billed");
   btn.IsEnabled = false;
}

I want the make the button disable on button click which is happening on button click event. But when I click on that disable button it gets enabled. I don't want to enable the button once it is disabled. How to do this? Can you please tell me where I am going wrong ? Or can you please provide me any code so that I can solve the above issue ?

Was it helpful?

Solution

I think you can achieve this by introducing binding of Button's IsEnable property to a boolean property in your ModelView. On MarkBilledButton_Click, set that property to FALSE, and even if refresh happened of the control, due the internal WPF framework message pumping, or due the some programming (which is not visible here), IsEnable property of the button will be read from ModelView.

Hope this helps.

OTHER TIPS

Since you want the button to be clickable after "disabling" it, you should probably not disable the button, since that will make it un-clickable. It seems like you want to make it look disabled but still be enabled.

My suggestion is that you modify the style of the button when the user clicks it rather than enabling/disabling it, so that the button looks and feels disabled but still reports click events.

For example you can change the background / foreground colors of the button.

Maybe you could put the code into an IF statement?

IF (  btn.IsEnabled = True )
{
   Button btn = sender as Button;
   //string buttonContent = btn.Content.ToString();
   MedwaiverTimeLog timeLogObj = btn.DataContext as MedwaiverTimeLog;
   MedwaiverViewModel MedwaiverViewModelObj = new MedwaiverViewModel();
   MedwaiverViewModelObj.ChangeBillingStatus(timeLogObj.ListItemId, "Billed");
   btn.IsEnabled = false;
}

There might be a better sollution but this is something quick and easy i thought off. I don't realy know why the button is behaving like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top