Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2395
Button command
posted

I am using xamDataGrid with fields A B and C.

A is numeric, B is enum field, C is unbound field which contains a button inside.

The button is used to change the value of A (let's say to increase by 1)

B is updated from the code behind and depending of B value the button in C should be enabled/disabled.

I am using the following template:

    <Style x:Key="OrderGridIncreaseStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{x:Static Themes:DataPresenterGeneric.CellValuePresenter}">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                        <Button Content="Increase" 
                                Command="my:MyClass.increasePrice" 
                    CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent},  Path=Record}"/>
           </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
private static void PriceChangeCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
var record = e.Parameter as DataRecord;
if (record == null)
{
e.CanExecute = false;
return;
}

var item = record.DataItem as MyCustomClass;
if (item == null)
{
e.CanExecute = false;
return;
}

e.CanExecute = item.Property == SomeValue) ;
}

The problem is: button IsEnabled state does not change as Field B value changes, it only changes when grid is clicked or keyboard key is pressed.
How to make the button enabled state change immediately?

the datasource is observablecollection and every property of datasource item implements INotifyPropertyChanged...

I can see field B value changing, but button state does not.
Parents
No Data
Reply Children