开发者

Why does VerticalScrollBarVisibility not work in a style in Silverlight?

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}"
                    />
        </StackPane开发者_如何学Cl>
    </Grid>
</UserControl>

In WPF it works works fine.

How can I get VerticalScrollBarVisibility to work in a style?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜