简体   繁体   English

TextBox样式不创建垂直滚动条

[英]TextBox Style Not Creating Vertical Scrollbar

I'm trying to create a style for my textbox, however when I add this template to the style the vertical scrollbars disappear. 我正在尝试为文本框创建样式,但是,当我将此模板添加到样式中时,垂直滚动条就会消失。

<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>

I noticed that you are wrapping the ScrollViewer in a ListBox . 我注意到您将ScrollViewer包装在ListBox The default template for a ListBox includes a ScrollViewer , so the interaction between them is most likely causing your ScrollBar issues. ListBox的默认模板包括ScrollViewer ,因此它们之间的交互很可能导致ScrollBar问题。

What are you trying to accomplish by putting the ScrollViewer in a ListBox in your TextBox template? 通过将ScrollViewer放在TextBox模板的ListBox中,您要完成什么工作? If we know why you are doing it, we can probably help you achieve the desired behavior. 如果我们知道您这样做的原因,则可能可以帮助您实现所需的行为。

The default template uses ListBoxChrome from the theme assembly to achieve the themed border look. 默认模板使用主题程序ListBoxChrome来实现主题边框外观。 If that is what you are after, this will work (note that you will need to add a reference to PresentationFramework.Aero): 如果这是您要执行的操作,那么它将起作用(请注意,您需要添加对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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM