0

I am creating a custom control which is derived from ItemsControl and now I am facing a problem. When I used my control at sample level with more item means, scrollviewer is not displayed(both H & V). Below is the code(Just sample) for my custom control:

<!--Parent-->
<Style TargetType="{x:Type local:Parent}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:Parent}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <ScrollViewer>  
                        <ItemsPresenter/>
                    </ScrollViewer>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<!--MainChild-->

<Style TargetType="{x:Type local:MainChild}">
    <Setter Property="Height" Value="430"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MainChild}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <ItemsPresenter />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<!--InnerChild-->
<Style TargetType="{x:Type local:InnerChild}">
    <Setter Property="Width" Value="100"/>
    <Setter Property="Height" Value="100"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:InnerChild}">
                --------------------------------------
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

I used the above control in my sample with many childrens, but scrollviewer is not displayed.

Sample having my control as,

<local:Parent Background="Yellow" >
<local:MainChild Margin="20" Background="Green">
    <local:InnerChild Content="Item1" Background="#FF008C00"/>
    <local:InnerChild Content="Item2" Background="#FF008C00"/>
    <local:InnerChild Content="Item3" Background="#FF008C00"/>
    <local:InnerChild Content="Item4" Background="#FF008C00"/>
    <local:InnerChild Content="Item5" Background="#FF008C00"/>
    <local:InnerChild Content="Item6" Background="#FF008C00"/>
    <local:InnerChild Content="Item7" Background="#FF008C00"/>
    <local:InnerChild Content="Item8" Background="#FF008C00"/>
</local:MainChild>
</local:Parent>

Like this i used it in sample and it extends horizontally, but no horizontal scroll bar is displayed.

Any suggestions are welcome?

Muthalagu
  • 156
  • 1
  • 16
  • Check out this answer: http://stackoverflow.com/questions/2783845/virtualizing-an-itemscontrol – Blablablaster Jun 24 '13 at 12:06
  • Can we also see how you using the Parent control. Because some panels like stackpanel will not allow its child to bring scrolling sometimes. So please post your XAML, how you using the Parent control. – Jawahar Jun 24 '13 at 12:27
  • XAML Lover-Please find the sample using my control(pasted in my initial post) – Muthalagu Jun 25 '13 at 05:20
  • I got the answer and i used the ItemsPanel, now it works fine. – Muthalagu Jun 26 '13 at 06:02

0 Answers0