2010-11-04 41 views
0

我試圖爲我的文本框創建樣式,但是當我將此模板添加到垂直滾動條消失的樣式時。TextBox樣式不創建垂直滾動條

<Style x:Key="MyTextBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}"> 
     <Setter Property="Foreground" Value="{DynamicResource BlueForegroundBrush}"/> 
     <Setter Property="BorderBrush" Value="Transparent"/> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="FontSize" Value="14"/> 
     <Setter Property="Padding" Value="0,-5,0,0"/> 
     <Setter Property="Width" Value="120"/> 
     <Setter Property="Height" Value="100"/> 
     <Setter Property="Focusable" Value="True"/> 
     <Setter Property="AllowDrop" Value="True"/> 
     <Setter Property="IsReadOnly" Value="True" /> 
     <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TextBox}"> 
        <Grid> 
         <Rectangle x:Name="_rct" Stroke="#FFA8AFBE" RadiusX="8" RadiusY="8" Fill="White" /> 
         <Border x:Name="_borderActive" BorderThickness="2" CornerRadius="8" BorderBrush="#FFA8AFBE" > 
          <ListBox x:Name="Bd" SnapsToDevicePixels="true" 
            Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" 
            BorderThickness="{TemplateBinding BorderThickness}" 
            Margin="6"> 
           <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
          </ListBox> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

回答

0

我注意到,您在ListBox包裹ScrollViewerListBox的默認模板包含ScrollViewer,因此它們之間的交互很可能會導致您的ScrollBar問題。

通過將ScrollViewer放入您的TextBox模板的ListBox中,您試圖完成什麼?如果我們知道你爲什麼這樣做,我們可以幫助你達到預期的行爲。

默認模板使用主題部件中的ListBoxChrome來實現主題邊框外觀。如果這是你以後的事情,這將工作(請注意,您將需要添加對PresentationFramework.Aero的引用):

<mwt:ListBoxChrome xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
        Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        RenderMouseOver="{TemplateBinding IsMouseOver}" 
        RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" 
        SnapsToDevicePixels="True"> 
    <ScrollViewer Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
</mwt:ListBoxChrome>