user593358
user593358

Reputation:

WPF: ItemsControl's border not visible

I followed the instruction in this blog to add ScrollIntoView 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

Upvotes: 1

Views: 2309

Answers (1)

Bas
Bas

Reputation: 27115

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>

Upvotes: 5

Related Questions