This is a migrated thread and some comments may be shown as answers.
Binding to IsExpanded with a ContainerBindingCollection
14 Answers 164 Views
This is a migrated thread and some comments may be shown as answers.
Dan Andrews
Top achievements
Rank 2
Dan Andrews asked on 10 Aug 2011, 02:27 PM
<UserControl.Resources>
    <t:ContainerBindingCollection x:Name="TreeListViewRowBindings">
        <!--<t:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" />-->
        <t:ContainerBinding PropertyName="IsExpanded" Binding="{Binding Mode=OneWay, Path=isExpanded}" />
    </t:ContainerBindingCollection>

I have tried with "Path" and not.  isExpanded is a property on my Model (which I hate because it's GUI), will change to a converter if I can get it working.

<t:RadTreeListView x:Name="CommodityGridView"
                   ItemsSource="{Binding Path=ParentLines, Mode=TwoWay, NotifyOnValidationError=True}"                       
                   ColumnWidth="Auto"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"
                   EnableColumnVirtualization="True"                       
                   RowIndicatorVisibility="Collapsed"
                   ShowGroupPanel="False"
                   AutoGenerateColumns="False"
                   CanUserFreezeColumns="False"
                   CanUserInsertRows="False"
                   CanUserDeleteRows="False" t:ContainerBinding.ContainerBindings="{StaticResource TreeListViewRowBindings}"
                   KeyUp="CommodityGridView_KeyUp"
                   IsBusy="{Binding IsBusy}" >

So what am I doing wrong?

14 Answers, 1 is accepted

Sort by
0
Dan Andrews
Top achievements
Rank 2
answered on 10 Aug 2011, 02:49 PM
All I really want to do is expand the list if there are more than one child and leave it collapsed if there is only one child.
0
Dan Andrews
Top achievements
Rank 2
answered on 10 Aug 2011, 03:45 PM
Even if I try this trick, I get the NullReference (same as if you bind to IsExpanded other ways)

<t:RadTreeListView.RowStyle >
    <Style TargetType="t:TreeListViewRow">
        <Setter Property="u:SetterValueBindingHelper.PropertyBinding">
            <Setter.Value>
                <u:SetterValueBindingHelper
                        Property="IsExpanded"
                        Binding="{Binding isExpanded}"/>
            </Setter.Value>
        </Setter>
    </Style>
</t:RadTreeListView.RowStyle>

But if I change the property to IsEnabled, the binding works as expected and doesn't throw an exception.  So the problem has to be in the IsExpanded.

Oh yeah, I also attempted to use the style selector but it too throws an exception...  RowLoad event shouldn't be my only choice.
0
Vlad
Telerik team
answered on 11 Aug 2011, 08:35 AM
Hi,

 Binding to IsExpanded property is not supported and indeed you can use RowLoaded or RowStyleSelector to achieve this. Can you post more info about the exception? Stack trace? 

Best wishes,

Vlad
the Telerik team

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

0
Dan Andrews
Top achievements
Rank 2
answered on 11 Aug 2011, 07:14 PM
XAML:

<u:CommodityRowStyle x:Key="collapseStyle">
    <u:CommodityRowStyle.CollapseStyle>
          
        <Style TargetType="t:TreeListViewRow">
            <Setter Property="IsExpanded" Value="False"/>
            <Setter Property="Background" Value="Green"/>
        </Style>
    </u:CommodityRowStyle.CollapseStyle>
    <u:CommodityRowStyle.ExpandedStyle>
        <Style TargetType="t:TreeListViewRow">
            <Setter Property="IsExpanded" Value="True"/>
            <Setter Property="Background" Value="Red"/>
        </Style>                
    </u:CommodityRowStyle.ExpandedStyle>
</u:CommodityRowStyle>

<t:RadTreeListView x:Name="CommodityGridView" 
                   ItemsSource="{Binding Path=ParentLines, Mode=TwoWay, NotifyOnValidationError=True}"                        
                   ColumnWidth="Auto" 
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Stretch"
                   EnableColumnVirtualization="True"                        
                   RowIndicatorVisibility="Collapsed" 
                   ShowGroupPanel="False" 
                   AutoGenerateColumns="False" 
                   CanUserFreezeColumns="False"
                   CanUserInsertRows="False" 
                   CanUserDeleteRows="False" 
                   KeyUp="CommodityGridView_KeyUp"
                   RowStyleSelector="{StaticResource collapseStyle}"
                   IsBusy="{Binding IsBusy}" >

StyleSelector:
public class CommodityRowStyle : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is FreightParentLineModel)
        {
            FreightParentLineModel parent = item as FreightParentLineModel;
            if (parent.children.Count > 1)
            {
                return ExpandedStyle;
            }
            else
            {
                return CollapseStyle;
            }
        }
        return null;
    }
    public Style CollapseStyle { get; set; }
    public Style ExpandedStyle { get; set; }
}

I get a Visual Studio Just-In-Time Debugger unhandled Error 4004, NULLReferenceException, object reference not set...

If I comment out the IsExpanded attribute, the colors are bound as expected.

0
Vlad
Telerik team
answered on 12 Aug 2011, 07:14 AM
Hello,

 Can you post the exception stack trace?

Best wishes,
Vlad
the Telerik team

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

0
Dan Andrews
Top achievements
Rank 2
answered on 12 Aug 2011, 01:19 PM
System.Exception crossed a native/managed boundary

Call Stack:
> System.ServiceModel.dll!System.ServiceModel.AsyncResult.Complete(bool completedSynchronously) + 0x11b bytes 
  System.ServiceModel.dll!System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStreamAsyncResult.OnGetRequestStream(System.IAsyncResult result) + 0x97 bytes 
  System.Windows.dll!System.Net.Browser.BrowserHttpWebRequest.InvokeGetRequestStreamCallback.AnonymousMethod__7(object state2) + 0x14 bytes 
  mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3d bytes 
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0x97 bytes 
  mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5b bytes 
  mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x199 bytes 
  mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes 
  [Native to Managed Transition] 
  [Appdomain Transition] 
  [Native to Managed Transition] 

Disassembly:

00000000 push ebp

00000001 mov ebp,esp

00000003 push edi

00000004 push esi

00000005 push ebx

00000006 sub esp,28h

00000009 mov esi,ecx

0000000b lea edi,[ebp-2Ch]

0000000e mov ecx,7

00000013 xor eax,eax

00000015 rep stos dword ptr es:[edi]

00000017 mov ecx,esi

00000019 xor eax,eax

0000001b mov dword ptr [ebp-18h],eax

0000001e mov dword ptr [ebp-24h],ecx

00000021 mov ecx,edx

00000023 mov eax,dword ptr [ebp-24h]

00000026 cmp byte ptr [eax+1Ah],0

0000002a jne 0007847C

00000030 mov eax,dword ptr [ebp-24h]

00000033 mov byte ptr [eax+18h],cl

00000036 movzx eax,cl

00000039 test eax,eax

0000003b je 00000046

0000003d mov eax,dword ptr [ebp-24h]

00000040 mov byte ptr [eax+1Ah],1

00000044 jmp 00000090

00000046 mov eax,dword ptr [ebp-24h]

00000049 mov edx,dword ptr [eax+14h]

0000004c mov dword ptr [ebp-28h],edx

0000004f mov ecx,edx

00000051 call FFF63EF8

00000056 mov eax,dword ptr [ebp-24h]

00000059 mov byte ptr [eax+1Ah],1

0000005d cmp dword ptr [eax+10h],0

00000061 je 00000070

00000063 mov eax,dword ptr [ebp-24h]

00000066 mov ecx,dword ptr [eax+10h]

00000069 cmp dword ptr [ecx],ecx

0000006b call FFF64248

00000070 mov dword ptr [ebp-1Ch],0

00000077 mov dword ptr [ebp-18h],0FCh

0000007e push 9A03703h

00000083 jmp 00000085

00000085 mov ecx,dword ptr [ebp-28h]

00000088 call FFF63F00

0000008d pop eax

0000008e jmp eax

00000090 mov eax,dword ptr [ebp-24h]

00000093 cmp dword ptr [eax+4],0

00000097 je 0000011B

0000009d xor edx,edx

0000009f mov dword ptr [ebp-2Ch],edx

000000a2 mov eax,dword ptr [ebp-24h]

000000a5 mov ecx,dword ptr [eax+4]

000000a8 mov edx,eax

000000aa mov eax,dword ptr [ecx+0Ch]

000000ad mov ecx,dword ptr [ecx+4]

000000b0 call eax

000000b2 mov dword ptr [ebp-1Ch],0

000000b9 mov dword ptr [ebp-18h],0FCh

000000c0 push 9A036B8h

000000c5 jmp 000000C7

000000c7 cmp dword ptr [ebp-2Ch],0

000000cb je 000000D5

000000cd xor ecx,ecx

000000cf call dword ptr ds:[09938530h]

000000d5 pop eax

000000d6 jmp eax

000000d8 mov dword ptr [ebp-18h],0

000000df jmp 0000011B

000000e1 mov dword ptr [ebp-30h],eax

000000e4 mov ecx,eax

000000e6 call FFFFC380

000000eb test eax,eax

000000ed je 000000F4

000000ef call FFF651A0

000000f4 mov edx,9931000h

000000f9 mov ecx,7000067Ch

000000fe call FFF65150

00000103 mov ecx,eax

00000105 call FFFEC5E0

0000010a mov ecx,eax

0000010c mov edx,dword ptr [ebp-30h]

0000010f call FFFF5EF0

00000114 mov ecx,eax

00000116 call FFF65158

0000011b lea esp,[ebp-0Ch]                                         <---------

0000011e pop ebx

0000011f pop esi

00000120 pop edi

00000121 pop ebp

00000122 ret

00000123 mov dword ptr [ebp-18h],0

0000012a jmp 00000090

0000012f mov ecx,9A5A560h

00000134 call FFEECD5B

00000139 mov dword ptr [ebp-34h],eax

0000013c mov ecx,eax

0000013e call FFEF2ABB

00000143 mov ecx,dword ptr [ebp-34h]

00000146 call FFEECE0B

0000014b int 3


{System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)}

StackTrace:
   at Telerik.Windows.Controls.GridView.GridViewItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)


0
Maya
Telerik team
answered on 17 Aug 2011, 02:27 PM
Hi Dan Andrews,

Generally, setting the IsExpanded property of the TreeListViewRow in row style selector is not quite good way to go. You may try to set it in the style selector. I am sending you a sample project illustrating the suggested approach. 
 

Best wishes,
Maya
the Telerik team

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

0
Dan Andrews
Top achievements
Rank 2
answered on 17 Aug 2011, 02:49 PM
I'll try it next.  Even Vlad suggested using RowStyleSelector above - it appears logical.  Hopefully the next version will make this functionality a little more intuitive.
0
Tim
Top achievements
Rank 1
answered on 24 Jan 2012, 05:46 PM
Hello! Any updates on this? The discussed solutions are really some kind of awkward! :)
0
Tim
Top achievements
Rank 1
answered on 24 Jan 2012, 06:30 PM
Addition:
Currently I am using version 2011.2.920.1040 - with this version the demo project from Maya is not working! Any help? Thanks a lot in advance!!! Tim.
0
Maya
Telerik team
answered on 27 Jan 2012, 02:30 PM
Hello Tim,

I am sending you an updated version of the sample that should work with the version you are using.
Let me know whether in case you need any further assistance.


Greetings,
Maya
the Telerik team

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

0
Tim
Top achievements
Rank 1
answered on 27 Jan 2012, 04:51 PM
Hello Maya,

thanks a lot for the updated project! It helped me a lot! Unfortunately I've used
<Style x:Key="EmptyStyle"  TargetType="telerik:GridViewToggleButton" telerik:StyleManager.BasedOn="Windows7">
     <Setter Property="PresentationMode" Value="PlusMinus"/>
</Style>
and now this style is overwritten and more unfortunate I wasn't able to set this style in code. How can I add this style in your SelectStyle method? Thanks a lot for any hint!

All the best and greetings,
Tim.
0
Maya
Telerik team
answered on 31 Jan 2012, 05:12 PM
Hi Dan,

I have tested the case and once I set the style to HierachyExpandButtonStyle and everything works as expected. I am attaching the sample project so that you can use it for a reference.
 

All the best,
Maya
the Telerik team

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

0
Tim
Top achievements
Rank 1
answered on 01 Feb 2012, 11:55 AM
Hi Maya,

thanks a lot for your answer! Until now, I didn't succeed to change the HierarchyExpandButtonStyle although my project now is more or less equal with your sample project. I'll need to further investigate - only wanted to say thanks and let you know that I appreciate your input! I'll post an update when I got it running...

All the best,
Tim.
Asked by
Dan Andrews
Top achievements
Rank 2
Answers by
Dan Andrews
Top achievements
Rank 2
Vlad
Telerik team
Maya
Telerik team
Tim
Top achievements
Rank 1
Share this question
or