VerticalScrollBarVisibility在我内联定义时可以正常工作:
<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>
但是当我将VerticalScrollBarVisibility放入样式时,它会显示一个空白屏幕:
<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>
在WPF中,它的工作正常。
如何让VerticalScrollBarVisibility以样式工作?
答案 0 :(得分:4)
它不起作用,因为这些属性不是依赖属性,不能用于样式。不幸的是,在ScrollViewer上使用附加属性也不起作用,因为它们不是默认样式的模板绑定。
我唯一能想到的就是创建一个附加行为,即在文本框中设置所需的值并通过样式应用它。