Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have a datagrid (wpftoolkit v3.5.40128.1).
can any one suggest me how to get ride of this problem....
if vertical scroll bar is visible the last column of a data grid is moved left to a size of scroll bar column.
I need my last column header overlaps the vertical scroll bar.
pls give me some idea either in xaml or code.
 
Note: i have used mvvm parten.
Posted 12-Feb-13 23:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

By editing the default template of the datagrid this problem can be solved.
<style targettype="{x:Type my:DataGrid}">
        <setter property="Background" value="Black" />
        <setter property="Template">
            <setter.value>
                <controltemplate targettype="{x:Type my:DataGrid}">
                    <border removed="{TemplateBinding Background}">
      BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}"
      SnapsToDevicePixels="True"
      Padding="{TemplateBinding Padding}">
                        <scrollviewer focusable="false">
                Name="DG_ScrollViewer">
                            <scrollviewer.template>
                                <controltemplate targettype="{x:Type ScrollViewer}">
                                    <grid>
                                        <grid.rowdefinitions>
                                            <rowdefinition height="Auto" />
                                            <rowdefinition height="*" />
                                            <rowdefinition height="Auto" />
                                        </grid.rowdefinitions>
 
                                        <grid.columndefinitions>
                                            <columndefinition width="Auto" />
                                            <columndefinition width="*" />
                                            <columndefinition width="Auto" />
                                        </grid.columndefinitions>
 
                                        <button command="{x:Static my:DataGrid.SelectAllCommand}">
                                Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type my:DataGrid}}, Path=CellsPanelHorizontalOffset}"
                                Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type my:DataGrid}, ResourceId=DataGridSelectAllButtonStyle}}"
                                Focusable="false"
                                Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type my:DataGrid}}, Path=HeadersVisibility, Converter={x:Static my:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static my:DataGridHeadersVisibility.All}}" />
                                        <my:datagridcolumnheaderspresenter grid.column="1" xmlns:my="#unknown">
                                           Name="PART_ColumnHeadersPresenter"
                                           Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type my:DataGrid}}, Path=HeadersVisibility, Converter={x:Static my:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static my:DataGridHeadersVisibility.Column}}"/>
 
                                        <scrollcontentpresenter x:name="PART_ScrollContentPresenter" grid.row="1" grid.columnspan="2" cancontentscroll="{TemplateBinding CanContentScroll}" xmlns:x="#unknown" />
 
                                        <scrollbar grid.row="1" grid.column="1" name="PART_VerticalScrollBar">
                                 Orientation="Vertical" HorizontalAlignment="Right" Margin="0,0,0,0" SnapsToDevicePixels="True" OverridesDefaultStyle="True"
                                 Maximum="{TemplateBinding ScrollableHeight}"
                                 ViewportSize="{TemplateBinding ViewportHeight}"
                                 Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                 Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}">
                                            <scrollbar.style>
                                                <style targettype="{x:Type ScrollBar}">
                                                    <setter property="SnapsToDevicePixels" value="True" />
                                                    <setter property="OverridesDefaultStyle" value="true" />
                                                    <style.triggers>                                                       
                                                        <trigger property="Orientation" value="Vertical">
                                                            <setter property="Width" value="18" />
                                                            <setter property="Height" value="Auto" />
                                                            <setter property="Template" value="{StaticResource VerticalScrollBar}" />
                                                        </trigger>
                                                    </style.triggers>
                                                </style>
                                            </scrollbar.style>
                                        </scrollbar>
 
                                        <grid grid.row="2" grid.column="1">
                                            <grid.columndefinitions>
                                                <columndefinition width="{Binding RelativeSource={RelativeSource AncestorType={x:Type my:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}" />
                                                <columndefinition width="*" />
                                            </grid.columndefinitions>
                                            <scrollbar grid.column="1">
                                       Name="PART_HorizontalScrollBar"
                                       Orientation="Horizontal"
                                       Maximum="{TemplateBinding ScrollableWidth}"
                                       ViewportSize="{TemplateBinding ViewportWidth}"
                                       Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}">
                                                <scrollbar.style>
                                                <style targettype="{x:Type ScrollBar}">
                                                    <setter property="SnapsToDevicePixels" value="True" />
                                                    <setter property="OverridesDefaultStyle" value="true" />
                                                    <style.triggers>
                                                            <trigger property="Orientation" value="Horizontal">
                                                                <setter property="Width" value="Auto" />
                                                                <setter property="Height" value="18" />
                                                                <setter property="Template" value="{StaticResource HorizontalScrollBar}" />
                                                            </trigger>
                                                        </style.triggers>
                                                </style>
                                                </scrollbar.style>
                                            </scrollbar>
 
                                        </grid>
                                    </my:datagridcolumnheaderspresenter></button></grid>
                                </controltemplate>
                            </scrollviewer.template>
                            <itemspresenter snapstodevicepixels="{TemplateBinding SnapsToDevicePixels}" />
                        </scrollviewer>
                    </border>
                </controltemplate>
            </setter.value>
        </setter>
    </style>
 
in the xaml code that i given,
PART_VerticalScrollBar is scrollbar.
i have altered the grid.column = 2 to grid.column = 1.
Happy codeing
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

By editing the default template of the datagrid this problem can be solved.
 
http://msdn.microsoft.com/en-us/library/cc278066(v=vs.95).aspx[^]
 
use the datagrid default template from above link.
find "VerticalScrollbar" is scrollbar.
you should alter the grid.column = 2 to grid.column = 1.
Happy codeing
  Permalink  
v2

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100