Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to style a vertical scrollbar for my textbox.

I am NOT allowed to add/use a style that is automatically used for all textboxes,
or scrollviewers, because I am not allowed to override anything common.

So I need a style with a key/name I can use for each textbox (or not).

Here my XAML code for styling the textbox:

HTML
<Style x:Key="PortalTextBox" TargetType="{x:Type TextBox}">
    <setter property="OverridesDefaultStyle" value="true" />
    <setter property="AllowDrop" value="true" />
    <setter property="MinWidth" value="0" />
    <setter property="MinHeight" value="0" />
    <setter property="FocusVisualStyle" value="{x:Null}" />
    <setter property="Template">
        <setter.value>
            <controltemplate targettype="{x:Type TextBox}">
                <!--<scrollviewer focusable="false" removed="Transparent" x:name="PART_ContentHost" horizontalscrollbarvisibility="Hidden" verticalscrollbarvisibility="Hidden" style="{StaticResource {ComponentResourceKey ResourceId=PortalScrollViewer, TypeInTargetAssembly=SiControls:SiCResourceKeys}}" xmlns:x="#unknown" />-->
                <!--<scrollcontentpresenter x:name="PART_ScrollContentPresenter" cancontentscroll="{TemplateBinding CanContentScroll}" canhorizontallyscroll="False" canverticallyscroll="False" contenttemplate="{TemplateBinding ContentTemplate}" content="{TemplateBinding Content}" grid.column="0" margin="{TemplateBinding Padding}" grid.row="0" xmlns:x="#unknown" />-->
                <scrollbar x:name="PART_VerticalScrollBar" automationproperties.automationid="VerticalScrollBar" cursor="Arrow" grid.column="1" minimum="0" grid.row="0" visibility="{TemplateBinding VerticalScrollBarVisibility}" value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" viewportsize="{TemplateBinding ActualHeight}" style="{StaticResource {ComponentResourceKey ResourceId=PortalVerticalScrollBarStyle, TypeInTargetAssembly=SiControls:SiCResourceKeys}}" xmlns:x="#unknown" />
            </controltemplate>
        </setter.value>
    </setter>
</Style>


I have already Styles for PortalVerticalScrollBarStyle and PortalHorizontalScrollBarStyle which are working (on a ScrollViewer).

I try to style the Textbox then:

HTML
<textbox x:name="txtAdditionalInstructions" horizontalalignment="Stretch" verticalalignment="Stretch" uselayoutrounding="True" fontsize="16" text="{Binding CurrentOrder.AdditionalInstructions, ElementName=AddExtraInformation}" height="322" acceptsreturn="True" acceptstab="True" margin="4,0,0,0" borderthickness="0" horizontalscrollbarvisibility="Hidden" verticalscrollbarvisibility="Auto" width="316" textwrapping="Wrap" style="{DynamicResource {ComponentResourceKey ResourceId=PortalTextBox, TypeInTargetAssembly=SiControls:SiCResourceKeys}}" xmlns:x="#unknown"></textbox>


But somehow it is not working.
I am also not sure for the texbox how the PART_Scroll.. stuff must look like.
Any idea what I am doing wrong? Thanks a lot!
Posted
Comments
EriBeh 29-Jul-11 5:56am    
Some additional info:

I can see my styled scrollbar in the textbox, the bindings are working.

But it is somehow wrong, it appears in the middle and is not scrolling.

So the error is in the Textbox style, somewhere at the "PART"... stuff,
I don't know how to use that exactly.

1 solution

Solution:

XML
<Style x:Key="PortalTextBox" TargetType="{x:Type TextBox}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="MinWidth" Value="0"/>
    <Setter Property="MinHeight" Value="0"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Template">
        <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true">
                    <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Style="{StaticResource {ComponentResourceKey ResourceId=PortalScrollViewer, TypeInTargetAssembly=SiControls:SiCResourceKeys}}"/>
                </Microsoft_Windows_Themes:ListBoxChrome>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>

        </Setter.Value>
    </Setter>
</Style>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900