Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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

By editing the default template of the datagrid this problem can be solved.
HTML
<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
 
Share this answer
 
v2
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
 
Share this answer
 
v2

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