TreeListView IsExpanded OneWay binding

8 posts, 0 answers
  1. Mickaël
    Mickaël avatar
    6 posts
    Member since:
    Oct 2011

    Posted 28 Mar 2012 Link to this post

    In a current project, we've used the TreeListView to display hierachical data (sreenshot attached).

    What we want to do is to expand all lines of a specific level.
    For example (see screenshot) :
     > when the user clicks on button "1", all "level 1" lines should expand
     > when the user clicks on button "2", all "level 1 and 2" lines should expand
    etc.

    We've succeeded doing this scenario with a Style Selector (already used for background coloration) :

    <styleSelectors:ConditionalStyleSelector.Level1Style>
         <Style TargetType="telerik:TreeListViewRow">
              <Setter Property="Background" Value="#6699FF" />
              <Setter Property="IsExpanded" Value="{Binding Path=IsExpandedLevel1, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=TwoWay}" />
         </Style>
    </styleSelectors:ConditionalStyleSelector.Level1Style>

    However, when the user collapses one "level 2" line (for example) all "level 2" lines are collasped.
    So we've changed the binding mode to "OneWay" :

    <Setter Property="IsExpanded" Value="{Binding Path=IsExpandedLevel1, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Mode=OneWay}" /> 

    However, with mode "OneWay" it doesn't work ...

    Any idea ? Or sample code to do this ?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Apr 2012 Link to this post

    Hello,

     Maybe you should rework the logic for collapsing in your model instead changing the binding from TwoWay to OneWay?

    Kind regards,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mickaël
    Mickaël avatar
    6 posts
    Member since:
    Oct 2011

    Posted 02 Apr 2012 Link to this post

    Hello,

    Certainly we can do some rework. However, I was wondering why the "OneWay" mode doesn't work as excepted.
    Do you have a bug logged on this ? Do you have a plan to correct it ? Any workaround ?

    Thanks
    Mickaël
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Apr 2012 Link to this post

    Hello,

    We are not sure if this is a bug in the component or something wrong with the logic behind this binding. Please send us an example demonstrating the problem - we will review your implementation and we will let you know about our findings. 

    Regards,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Mickaël
    Mickaël avatar
    6 posts
    Member since:
    Oct 2011

    Posted 10 Apr 2012 Link to this post

    Hello,

    Thanks for your answer.
    Please find a "quick and dirty" sample to reproduce this behavior on : https://skydrive.live.com/redir.aspx?cid=541ade983cd620b1&resid=541ADE983CD620B1!151&parid=541ADE983CD620B1!149&authkey=!AF8cT2J0N5rWZK0

    TwoWay binding is put on level 1. But, when the user collapses one "level 1" line (for example) all "level 1" lines are collasped.)
    OneWay binding is put on level 2. But rows don't collapse when user clicks on button 2.

    Thanks
    Mickaël
  7. Vera
    Admin
    Vera avatar
    263 posts

    Posted 11 Apr 2012 Link to this post

    Hi Mickaël,

     
    Actually, the behavior in both cases is expected. When TwoWay binding is set and a particular level is collapsed using the expander, the IsExpanded value is changed and all the rows from that level are collapsed. When OneWay binding is used, collapsing using the expander affects only the chosen row. But in that case you cannot use the implemented logic for the buttons' click events because it will not result in expanding/collapsing the items.
    You can find some more information here.


    Greetings,

    Vera
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Mickaël
    Mickaël avatar
    6 posts
    Member since:
    Oct 2011

    Posted 11 Apr 2012 Link to this post

    Hello,

    Thanks for this answer. However I really don't understand why this is the expected behavior
    In the OneWay mode, when the source changes (ie: the ViewModel) then the target property should be updated. This is not the case for "IsExpanded" property.

    Moreover, it works perfectly if you use "IsEnabled" property instead of "IsCollapsed".
    Any other explanations ?

    Regards,
    Mickaël
  9. Vera
    Admin
    Vera avatar
    263 posts

    Posted 12 Apr 2012 Link to this post

    Hello Mickaël,


    I have modified your project in order to demonstrate how the logic you have implemented works with MS TreeView. As you can see, the behavior is the same as the one when TreeListView is used. When OneWay mode is set, changing the IsExpanded value will affect the items only in case you have not expanded/collapsed them using the expander. You will need to revise your logic in order to achieve your goal.

     
    Greetings,
    Vera
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready