locked
How To Override a ListViews ScrollViewer Style? RRS feed

  • Question

  • Hi, I have resource dictionary that defines a new control template for a scrollviewer.  In my app.xaml I set a style that uses this template, and set it without a key so that all ScrollViewers use it (shown below).

    <!--ScrollViewer Control Template Override--> 
                <Style TargetType="{x:Type ScrollViewer}"
                    <Setter Property="OverridesDefaultStyle" Value="True" /> 
                    <Setter Property="Template" Value="{StaticResource NewScrollTemplate}" /> 
                </Style> 

    Now all the scrollviewers in the app use the new style except the ones that are in a ListView.  Why? How can I make that one use the template?  I dont want to define a control template for the Listview either.

    What am I missing?

    Thanks


    Tuesday, August 26, 2008 2:35 PM

Answers

  • It appears as if the default style for a ListView defines its own style for the ScrollViewer.  If you open Expression Blend, drop a ListView on a Window, choose EditTemplate, you can view the default style/template for the ListView.  The XAML for this default style includes a ControlTemplate which has a ScrollViewer defined like this:

    <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}" Padding="{TemplateBinding Padding}"
        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
    </ScrollViewer> 

    There is also a supporting style for the ScrollViewer that is added to your project in Blend.

    This means that, in order to override this default ListView ScrollViewer style, you will have to define your own ControlTemplate for the ListView that uses your ScrollViewer style (or doesn't define a style).

    Hope this helps,
    Brian

    Brian Schwalm • www.anythinksolutions.com
    • Marked as answer by Nithos Tuesday, August 26, 2008 5:13 PM
    Tuesday, August 26, 2008 3:09 PM

All replies

  • It appears as if the default style for a ListView defines its own style for the ScrollViewer.  If you open Expression Blend, drop a ListView on a Window, choose EditTemplate, you can view the default style/template for the ListView.  The XAML for this default style includes a ControlTemplate which has a ScrollViewer defined like this:

    <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}" Padding="{TemplateBinding Padding}"
        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
    </ScrollViewer> 

    There is also a supporting style for the ScrollViewer that is added to your project in Blend.

    This means that, in order to override this default ListView ScrollViewer style, you will have to define your own ControlTemplate for the ListView that uses your ScrollViewer style (or doesn't define a style).

    Hope this helps,
    Brian

    Brian Schwalm • www.anythinksolutions.com
    • Marked as answer by Nithos Tuesday, August 26, 2008 5:13 PM
    Tuesday, August 26, 2008 3:09 PM
  • Ok, great

    I can do that and add my style to the scrollviewer there, and that does work, however my listview looses all headers when i override the template.

    I'm not doing anything to the template than what is in the default so I dont know why I would loose the headers completely.

    Any Ideas?

    This whole control template is still pretty new to me.

    Never mind, the ScrollViewer template for the listview differs a bit thats why it wasnt working for me.

    Thanks for the help
    • Edited by Nithos Tuesday, August 26, 2008 5:14 PM found solution
    Tuesday, August 26, 2008 3:34 PM