开发者

WPF: ItemsControl's border not visible

I followed the instruction in this blog to add S开发者_Python百科crollIntoView to ItemsControl.

But this makes the border invisible:

<ItemsControl BorderBrush="Black"
              BorderThickness="3">
    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer Padding="{TemplateBinding Padding}">
                <ItemsPresenter />
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    <TextBlock Text="Test" />
    <TextBlock Text="Test" />
    <TextBlock Text="Test" />
</ItemsControl>

In order to display the border, I have to remove:

<ItemsControl.Template>
    <ControlTemplate>
        <ScrollViewer Padding="{TemplateBinding Padding}">
            <ItemsPresenter />
        </ScrollViewer>
    </ControlTemplate>
</ItemsControl.Template>

But this way I won't be able to use the ScrollIntoView method.

Any ideas? Thanks


You need to include the border in the template.

                <ControlTemplate>
                    <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                        <ScrollViewer Padding="{TemplateBinding Padding}">
                            <ItemsPresenter />

                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜