Why does VerticalScrollBarVisibility not work in a style in Silverlight?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2010-05-22T13:51:38Z Indexed on 2010/05/22 17:10 UTC
Read the original article Hit count: 243

VerticalScrollBarVisibility works when I define it inline like this:

<UserControl x:Class="TestScrollBar.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <UserControl.Resources>
        <Style TargetType="TextBox" x:Key="EditListContainerContentMultiLineTwoColumn">
            <Setter Property="AcceptsReturn" Value="True"/>
            <Setter Property="Width" Value="400"/>
            <Setter Property="Height" Value="300"/>
            <Setter Property="IsReadOnly" Value="False"/>
            <Setter Property="Margin" Value="0 0 0 20"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" Margin="10">
        <StackPanel HorizontalAlignment="Left">
            <TextBox Text="this is a test" 
                     Style="{StaticResource EditListContainerContentMultiLineTwoColumn}"
                     VerticalScrollBarVisibility="Auto"
                    />
        </StackPanel>
    </Grid>
</UserControl>

But when I put VerticalScrollBarVisibility in a style, it shows me a blank screen:

<UserControl x:Class="TestScrollBar.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <UserControl.Resources>
        <Style TargetType="TextBox" x:Key="EditListContainerContentMultiLineTwoColumn">
            <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="AcceptsReturn" Value="True"/>
            <Setter Property="Width" Value="400"/>
            <Setter Property="Height" Value="300"/>
            <Setter Property="IsReadOnly" Value="False"/>
            <Setter Property="Margin" Value="0 0 0 20"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" Margin="10">
        <StackPanel HorizontalAlignment="Left">
            <TextBox Text="this is a test" 
                     Style="{StaticResource EditListContainerContentMultiLineTwoColumn}"
                    />
        </StackPanel>
    </Grid>
</UserControl>

In WPF it works works fine.

How can I get VerticalScrollBarVisibility to work in a style?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about Silverlight