samedi 5 mars 2016

wpf Datagrid Checkbox NotifyOnTargetUpdated not works

My Class:

    public class BarCode : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    public string code { get; set; }
    public string name { get; set; }
    public Visibility special1 { get; set; }
    public Visibility special2 { get; set; }
    private bool _x1, _x2;
    public bool x1
    {
        get
        {
            return _x1;
        }
        set
        {
            if (value && _x2)
                _x2 = false;
            _x1 = value;
            OnPropertyChanged("X1");
        }
    }
    public bool x2
    {
        get
        {
            return _x2;
        }
        set
        {
            if (value && _x1)
                _x1 = false;
            _x2 = value;
            OnPropertyChanged("X2");
        }
    }
}

XAML:

                <DataGridTemplateColumn Header="X">
                <DataGridTemplateColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="Visibility" Value="{Binding special1}"></Setter>
                    </Style>
                </DataGridTemplateColumn.CellStyle>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding Path=.x1, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
            <DataGridTemplateColumn Header="X">
                <DataGridTemplateColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="Visibility" Value="{Binding special2}"></Setter>
                    </Style>
                </DataGridTemplateColumn.CellStyle>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox IsChecked="{Binding Path=.x2, UpdateSourceTrigger=PropertyChanged, NotifyOnTargetUpdated=True}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

I have two Checkboxes. When the first is checked and i want to check the second one, then the first one shall dischecking. But it will not upadeting. The check mark leaves only when im scrolling out of the visibility.




Aucun commentaire:

Enregistrer un commentaire