Can't use UserControl inside ItemsControl
Last post 05-11-2008 2:30 PM by kgalenko. 2 replies.
Sort Posts:
05-07-2008 11:00 PM
Can't use UserControl inside ItemsControl

 If I use UserControl as a template for ItemsControl like:

    <Canvas x:Name="LayoutRoot" >
        <ItemsControl x:Name="MyGroup">
            <ItemsControl.Template>
                <ControlTemplate TargetType="ItemsControl">
                    <Border BorderBrush="Aqua" BorderThickness="1" >
                    <ItemsPresenter />
                    </Border>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="Info" Foreground="Beige" />
                        <My_Print:Info />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Canvas>
 

and bind it to any collection I get exception AccessViolationException. But if I remove UserControl from StackPanel it works as expected.

kgalenko

Joined on 03-04-2008
Posts 14
05-08-2008 1:59 AM
Marked as Answer
Re: Can't use UserControl inside ItemsControl

There seems to be an issue with the UserControl in SL 2 Beta. In the case of the user control in the DataTemplate, you need to reference the assembly too in the namespace declaration even if it is in the same assembly. I guess your namespace declaration now is something like: 

xmlns:My_Print="clr-namespace:SilverlightApplication2"

 Change this to:

xmlns:My_Print="clr-namespace:SilverlightApplication2;assembly=SilverlightApplication2"

Hope this helps,
Jim (http://jimmangaly.blogspot.com/)

Please MARK the replies as answers if they answered your question

 

http://www.identitymine.com/

Jim Mangaly

Joined on 04-21-2008
Kochi, India
Posts 108
05-11-2008 2:30 PM
Re: Can't use UserControl inside ItemsControl

 Thanks a lot. That works.

kgalenko

Joined on 03-04-2008
Posts 14