2010-05-22 74 views
2

VerticalScrollBarVisibility的作品時,我的內聯定義它是這樣的:爲什麼VerticalScrollBarVisibility在Silverlight中的樣式中不起作用?

<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以使用樣式?

回答

4

它不工作,因爲這些屬性不是依賴關係,不能與樣式一起使用。不幸的是,在ScrollViewer上使用附加屬性也不起作用,因爲它們不是默認樣式的模板綁定。

我能想到的唯一能做的就是創建一個附加行爲,在文本框中設置所需的值並通過樣式應用它。

相關問題