views:

130

answers:

1

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"&gt;
    <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"&gt;
    <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?

+2  A: 

It is not working because these properties are not dependency ones and cannot be applied with style. Unfortunately using the attached property on the ScrollViewer is also not working, because they are not template bound in the default style.

The only thing I can think of you can do is to create an attached behavior that is setting the required values on the text box and apply it through the style.

ligaz