hi ,
i had edited the style of xamdatagrid label presenter.iam adding columns from my viewmodel and assigning the label presenter style to some columns.
but when i bind collection to grid, if header name exeeds 9 characters it will not show full header and sortindicator .
my label presenter style is as follows
<Style x:Key="HeaderWithCombo" TargetType="{x:Type igDP:LabelPresenter}"> <Setter Property="Padding" Value="5,4,5,4" /> <Setter Property="Background" Value="White"/> <Setter Property="LabelHighlight" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, LabelHighlight}}" /> <Setter Property="InnerBorderBrush" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, LabelInnerBorder}}" /> <Setter Property="OuterBorderBrush" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, LabelOuterBorder}}" /> <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, LabelForeground}}"/> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:LabelPresenter}"> <ControlTemplate.Resources> <Storyboard x:Key="sbHighlightOff"> <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="highlight"> <SplineDoubleKeyFrame Value="0" KeyTime="00:00:00.25"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </ControlTemplate.Resources>
<Grid Background="White" x:Name="mainGrid"> <Rectangle Stroke="DarkGray" StrokeThickness="1" RadiusX="1.55015910897703" RadiusY="1.55015910897703" Fill="Transparent" Margin="0,0,0,0" x:Name="lineOuter" Height="Auto" /> <Rectangle StrokeThickness="0" RadiusX="0.550159108977027" RadiusY="0.550159108977027" Fill="Transparent" Margin="1,1,1,1" x:Name="lineInner" Height="Auto" /> <Grid Margin="{TemplateBinding Padding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="sortIndicatorAndLabel">
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="5"/> <ColumnDefinition Width="30"/> </Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="Auto" ></ColumnDefinition> </Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0" HorizontalAlignment="Left" x:Name="LabelContent" Focusable="False" Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" VerticalAlignment="Center"/>
<igWindows:SortIndicator Grid.Column="1" HorizontalAlignment="Left" x:Name="SortIndicator" SortStatus="{TemplateBinding SortStatus}" Visibility="Hidden" VerticalAlignment="Center" Width="10" Foreground="DarkGray" />
</Grid>
<Rectangle Grid.Column="1" Width="1" Fill="Gray" HorizontalAlignment="Right" ></Rectangle>
<ComboBox Grid.Column="2" x:Name="FilterCombo" HorizontalAlignment="Right" Style="{StaticResource HeaderCombo}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}, Mode=FindAncestor},Path=DataSource}" DisplayMemberPath="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:LabelPresenter},Mode=FindAncestor},Path=Field.BindingPath}" HorizontalContentAlignment="Right" Width="30" BorderBrush="{x:Null}">
<tp:CommandTrigger.CommandTriggers> <tp:EventCommandTrigger Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.Commands.FilterComboChange }" Event="ComboBox.SelectionChanged"/> </tp:CommandTrigger.CommandTriggers>
</ComboBox>
</Grid> </Grid>
<ControlTemplate.Triggers> <DataTrigger Binding="{Binding Path=Field.LabelTextAlignmentResolved, RelativeSource={RelativeSource Self}}" Value="Center"> <Setter Property="HorizontalAlignment" TargetName="sortIndicatorAndLabel" Value="Center"/> </DataTrigger>
<Trigger Property="HorizontalAlignment" Value="Center"> <Setter Property="VerticalAlignment" TargetName="SortIndicator" Value="Top"/> <Setter Property="HorizontalAlignment" TargetName="SortIndicator" Value="Center"/> <Setter Property="Margin" TargetName="SortIndicator" Value="0,5,0,0"/> </Trigger>
<MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> </MultiTrigger.EnterActions> <MultiTrigger.ExitActions> </MultiTrigger.ExitActions> </MultiTrigger>
<Trigger Property="SortStatus" Value="Ascending"> <Setter TargetName="SortIndicator" Property="Visibility" Value="Visible" /> </Trigger> <Trigger Property="SortStatus" Value="Descending"> <Setter TargetName="SortIndicator" Property="Visibility" Value="Visible" /> </Trigger> </ControlTemplate.Triggers>
</ControlTemplate> </Setter.Value> </Setter> </Style>
really struggled with thise,so pls share me if any idea..
thanks.....
Hi slavi,
thanks for ur post and its working fine..
Regards,
Jafar VM
Hi Jafar,
I tried using the style you provided. If I understand correctly the Sort Indicator is not visible because when the header name exceeds 9 characters the initial column width is not enough to display the text, the sort indicator and the filter combo you are using. One way to solve this is to use the XamDataGrid’s auto size functionality. Here is an example how you can do that:
<igDP:XamDataGrid Name="xamDataGrid" >
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AutoSizeOptions="All" Width="Auto" AutoSizeScope="AllRecords"/>
</igDP:XamDataGrid.FieldSettings>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" />
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:UnboundField BindingPath="Age" Label="AgeAgeAgeAgeAgeAge"/>
<igDP:UnboundField BindingPath="Name" Label="Name"/>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Please let me know if this works for you or if I misunderstood your problem.
Thanks,
Slavi