Ticket T707274
Visible to All Users

DependencyProperty is not getting called on changing the treelist source.

created 6 years ago

Hi,

I am using dependency property to update checkbox values in tree list.

My code is as below:

C#
public static readonly DependencyProperty Val1Property = DependencyProperty.RegisterAttached("Val1", typeof(bool), typeof(frmECISOCode), new PropertyMetadata(false)); public static bool GetVal1(DependencyObject obj) { return (bool)obj.GetValue(Val1Property); } public static void SetVal1(DependencyObject obj, bool value) { obj.SetValue(Val1Property, value); } // Using a DependencyProperty as the backing store for Val2. This enables animation, styling, binding, etc... public static readonly DependencyProperty Val2Property = DependencyProperty.RegisterAttached("Val2", typeof(bool), typeof(frmECISOCode), new PropertyMetadata(false)); public static bool GetVal2(DependencyObject obj) { return (bool)obj.GetValue(Val2Property); } public static void SetVal2(DependencyObject obj, bool value) { obj.SetValue(Val2Property, value); }

My code in xaml file:

C#
<dxg:TreeListColumn Header="Is Redundant" FieldName="ColIsRedundantCode" UnboundType="Boolean" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" > <dxg:TreeListColumn.CellTemplate> <DataTemplate > <dxe:CheckEdit x:Name="PART_Editor" Visibility="{Binding RowData.Row ,Converter={StaticResource ChildNodeVisibilityConverter}}" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </DataTemplate> </dxg:TreeListColumn.CellTemplate> </dxg:TreeListColumn> <dxg:TreeListColumn Header="Is Secondary" FieldName="ColIsSecondaryId" UnboundType="Boolean" Binding="{Binding ColIsSecondaryId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <dxg:TreeListColumn.CellTemplate > <DataTemplate> <dxe:CheckEdit x:Name="PART_Editor" Visibility="{Binding RowData.Row ,Converter={StaticResource ChildNodeVisibilityConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center" IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </DataTemplate> </dxg:TreeListColumn.CellTemplate> </dxg:TreeListColumn>

These code works fine at the time of loading.

But when I re-assign the list to treelist itemsource then check boxes are not getting binded. It looks like on rebinng the grid does not call these dependency properties.

Can you please let me know the actual cause?

Thanks,
Ripal

Comments (3)

    Hi,

    I also face this issue when I try to add or remove child node. When I try to do that then checkbox gets unchecked.

    On scrolling heck boxes get checked again.

    Kirill (DevExpress Support) 6 years ago

      Hello,
      I've reviewed your code snippet and see that you bind your columns to one data item field using the FieldName/Binding property, but bind CheckEdit to another custom attached property.
      For example, your first TreeListColumn is bound to the ColIsRedundantCode field, but CheckBox is bound to the frmECISOCode.Val1  property:

      XAML
      <dxg:TreeListColumn FieldName="ColIsRedundantCode" ... />
      XAML
      <dxe:CheckEdit x:Name="PART_Editor" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

      In this case, your column contains data from a real item property but doesn't edit it and it's not fully clear why it's necessary to configure your columns in this way. Would you please clarify why you need to configure TreeListColumns in this way?

      Moreover, you set both the FieldName  and Binding  properties to the same field of your data item:

      XAML
      <dxg:TreeListColumn FieldName="ColIsRedundantCode" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >

      So, TreeListColumn uses two data obtaining mechanisms at once and this may cause data editing and synchronization issues. If you bind TreeListColumn using the Binding property, the FieldName property shouldn't refer to real data fields at your data item level. For example:

      XAML
      <dxg:TreeListColumn FieldName="CustomColIsRedundantCode" Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >

      Otherwise, remove the Binding property declaration and keep the FieldName property value only.

      According to these points, your overall scenario isn't clear to us, so please describe it in greater detail: why you're using attached properties Val1 and Val2,  where their values are stored, how they affect data items. At first glance, you need a column with CheckEdits with states that aren't bound to real data. In this case, I suggest that you take a look at our Unbound Columns feature.

      Thanks,
      Kirill

        Hi,

        I have written binding code, so that values can get binded from from database. If I do not write this code then values from DB do not get binnded.Binding="{Binding ColIsRedundantCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        These two lines are being used to get enable/disable check boxes.

        XAML
        <dxe:CheckEdit x:Name="PART_Editor" IsChecked="{Binding Path=RowData.RowState.(local:frmECISOCode.Val1), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Path=RowData.RowState.(local:frmECISOCode.Val2), Converter={dxmvvm:BooleanNegationConverter}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

        I have also attached snapshot of UI.

        Answers approved by DevExpress Support

        created 6 years ago (modified 6 years ago)

        Hello,
        Thank you for the clarification. It's not necessary to introduce additional attached properties to accomplish this task. Simply bind CheckEdit's IsEnabled property to another column. For example:

        XAML
        <dxg:GridColumn FieldName="IsChecked"> <dxg:GridColumn.CellTemplate> <DataTemplate> <dxe:CheckEdit Name="PART_Editor" IsEnabled="{DXBinding !RowData.Row.IsSelected}"/> </DataTemplate> </dxg:GridColumn.CellTemplate> </dxg:GridColumn> <dxg:GridColumn FieldName="IsSelected"> <dxg:GridColumn.CellTemplate> <DataTemplate> <dxe:CheckEdit Name="PART_Editor" IsEnabled="{DXBinding !RowData.Row.IsChecked}"/> </DataTemplate> </dxg:GridColumn.CellTemplate> </dxg:GridColumn>

        In this case, the "IsChecked" CheckEdit will be disabled when the "IsSelected" CheckEdit is checked and vice versa. See the attached screencast demonstrating this behavior. So, you can use the same approach on your side for the "ColIsRedundantCode" and "ColIsSecondaryId" columns.

        As you can see, this approach doesn't force you to do the following:

        1. use both the FieldName and Binding properties;
        2. create additional attached properties;
        3. bind the IsChecked property in CellTemplate.

        Note that I've used our DXBinding to avoid defining BooleanNegationConverter or another similar converter. Also, it's necessary to set TableView's EnableImmediatePosting property to immediately post values and enable/disable CheckEdits.

        Thanks,
        Kirill

          Comments (2)

            Hi,

            Thanks it worked.

            But now I want to enable checkbox based on two condition i.e.

            Code
            [C#]Open in popup window

            I want to enable isselected checkbox only if IsChecked  is checked and FieldIsEnable is unchecked.

            How to implement it?

            Kirill (DevExpress Support) 6 years ago

              Hello,
              Even in the case of complex conditions, you can use the approach with binding the CheckEdit's IsEnabled property. Besides the regular WPF MultiBinding (see the Introduction to Multi-binding and Multi-value Converters using IMultiValueConverter and MultiBinding article for details), you can continue using our DXBinding which also supports such logical operators as "And":

              XAML
              <dxg:GridColumn FieldName="IsEnabled"> <dxg:GridColumn.CellTemplate> <DataTemplate> <dxe:CheckEdit Name="PART_Editor" IsEnabled="{DXBinding !RowData.Row.IsChecked and RowData.Row.IsSelected}"/> </DataTemplate> </dxg:GridColumn.CellTemplate> </dxg:GridColumn>

              Please take a moment to review the Language Specification article describing the supported functions and operators.

              Thanks,
              Kirill

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.