locked
Change ScrollBar Style of ListBox RRS feed

  • Question

  • Hi All,

    I need t change the scrollBar style of some LISTBOX.

    Any Suggestion Would be of great help.

    Thanks



    Arjun

    • Changed type Xavier Xie-MSFT Sunday, August 28, 2016 7:28 AM it's a question
    Tuesday, August 9, 2016 9:49 AM

All replies

  • You could put an implicit custom ScrollBar style in the Resources dictionary of the ListBox, e.g.:

    <ListBox x:Name="lb" Height="50">
                <ListBox.Resources>
                    <Style TargetType="ScrollBar">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ScrollBar">
                                    <TextBlock>I am a ScrollBar!</TextBlock>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.Resources>
            </ListBox>

    You could copy the default style/template of the ScrollBar by adding a <ScrollBar /> element to your XAML markup, switch to design mode and choose Edit Template->Edit a Copy in Visual Studio 2012 or later. You can then edit the style/template as per your requirements before you add it to the Resources section of the ListBox as per above. Don't forget to remove the x:Key attribute from the Style in order to make it an implicit style. Please refer to the following links for more information about implicit styles:
    https://blogs.msdn.microsoft.com/wpfsdk/2009/08/27/implicit-styles-templates-controls-and-frameworkelements/
    https://wpf.2000things.com/tag/implicit-style/
    https://msdn.microsoft.com/en-us/library/ms745683%28v=vs.110%29.aspx


    Hope that helps.

    Please change the type of this thread from discussion to question and please also remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Tuesday, August 9, 2016 4:51 PM