Strange behavior of GridSplitter - wpf

can say that I am a beginner in WPF.
I have a strange behavior of GridSplitter; the grid is divided into 5 roww.
tabbar
horizontal grid
splitter
another tabbar
a textbox (txtLog)
like code below, but when I moving the separator the txtLog moves down instead of following the previous tabbar.
XAML:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MSCSimulator"
mc:Ignorable="d"
FontSize="14"
Title="Simulator"
Height="500" Width="800"
WindowStartupLocation="CenterScreen"
WindowStyle="ThreeDBorderWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="*" MinHeight="120" />
<RowDefinition Height="10" />
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="*" MinHeight="120" />
</Grid.RowDefinitions>
<!-- TOOLBAR -->
<ToolBarTray Margin="10,10,10,10" Width="Auto" Height="30">
<ToolBar Width="Auto" Height="30">
<Button Click="Send_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/Simulator;component/Images/play.png" Width="12" Height="12" />
<Label Padding="5,0,0,0">Invia</Label>
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" MinWidth="150" MaxWidth="220" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TreeView Width="Auto" Margin="10,0,0,0">
<TreeViewItem Header="Commands" IsExpanded="True">
<!-- APPLICATION -->
<TreeViewItem Header="Application">
<TreeViewItem Header="Simulate" MouseDoubleClick="Application_Simulate_MouseDoubleClick" />
<TreeViewItem Header="Update" MouseDoubleClick="Application_Update_MouseDoubleClick" />
</TreeViewItem>
</TreeViewItem>
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter Property="FontWeight" Value="Normal"/>
</Trigger>
</Style.Triggers>
</Style>
</TreeView.Resources>
</TreeView>
<GridSplitter Width="10"
Background="White"
VerticalAlignment="Stretch"
ResizeBehavior="BasedOnAlignment" />
<!-- JSON -->
<TextBox Name="txtJSON"
Grid.Column="2"
Background="White"
TextWrapping="Wrap"
AcceptsReturn="True"
Margin="-10,0,10,0"
VerticalScrollBarVisibility="Visible"
Width="Auto" Height="Auto" />
</Grid>
<GridSplitter Grid.Row="2"
Height="10"
ResizeDirection="Rows"
HorizontalAlignment="Stretch"
ResizeBehavior="PreviousAndNext"
Background="White"/>
<!-- TOOLBAR -->
<ToolBarTray Grid.Row="3" Margin="10,0,10,0" Width="Auto" Height="30" VerticalAlignment="Top">
<ToolBar Width="Auto" Height="30">
<Button Click="Clear_Click">
<StackPanel Orientation="Horizontal">
<Image Source="/Simulator;component/Images/clear.png" Width="16" Height="16" />
<Label Padding="5,0,0,0">Cancella</Label>
</StackPanel>
</Button>
</ToolBar>
</ToolBarTray>
<!-- LOGGER-->
<TextBox Name="txtLog"
Grid.Row="4"
TextWrapping="Wrap"
Margin="10,-10,10,10"
AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
Width="Auto" Height="Auto"
IsReadOnly="True">
<TextBox.Background>
<SolidColorBrush Color="#282828"></SolidColorBrush>
</TextBox.Background>
<TextBox.Foreground>
<SolidColorBrush Color="White"></SolidColorBrush>
</TextBox.Foreground>
</TextBox>
</Grid>
thanks advance

In your outer Grid, try to put the Height from * to Auto in the second RowDefinition
...
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" MinHeight="50" />
<RowDefinition Height="Auto" MinHeight="120" />
<RowDefinition Height="10" />
<RowDefinition Height="50" MinHeight="50"/>
<RowDefinition Height="*" MinHeight="120" />
</Grid.RowDefinitions>
<!-- TOOLBAR -->
...

Related

Scrollviewer with dynamic height and menu below

I cannot find any example how to implement a scrollviewer that contains a form, with the save/cancel buttons directly underneath and not separated at the bottom of the window here is a simple layout. I need to support resizing the window. I have many different lengths of forms, I want the scrollviewer to be as small as possible, and fill available space only if needed (if the form is larger). I don't want the buttons to always be pushed to the bottom of the window Not like this!, but to hug closer to the form (in the case of a shorter form) Something like this.
In my grid, I have a row for the ScrollViewer, a row for the buttons, and a row to fill remaining space (if any).
I understand that by setting the row height=Auto kills the ScrollViewer. How can I implement this then? Is this even possible?
Jeff -> Here is an image showing the window height increased. And an image showing the window height decreased, the buttons can disappear from view, and the scrollviewer overflows so that you cannot see all of it
<Window x:Class="WpfAppRenderPathGeometry.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfAppRenderPathGeometry"
mc:Ignorable="d"
Title="MainWindow" Height="500" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" x:Name="ScrollRow"/>
<RowDefinition Height="80" x:Name="ButtonsRow"/>
<RowDefinition Height="*" x:Name="SpaceRow"/>
</Grid.RowDefinitions>
<ScrollViewer x:Name="MyScroll" VerticalScrollBarVisibility="Visible">
<Grid x:Name="MyForm">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Column="1"></TextBox>
<TextBlock Grid.Row="1" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="1" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="2" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="2" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="3" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="3" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="4" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="4" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="5" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="5" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="6" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="6" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="7" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="7" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="8" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="8" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="9" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="9" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="10" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="10" Grid.Column="1"></TextBox>
<TextBlock Grid.Row="11" Grid.Column="0">LABEL</TextBlock>
<TextBox Grid.Row="11" Grid.Column="1"></TextBox>
</Grid>
</ScrollViewer>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1">
<Button>CANCEL</Button>
<Button>SAVE</Button>
</StackPanel>
</Grid>
</Window>
As an example, I think this will do what you want - just adjust as you need.
I adjusted again but I am not sure I understand your intent.
<Window
x:Class="WpfSubDivideWindow.ScrollViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfSubDivideWindow"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:MyNamespace="clr-namespace:WpfSubDivideWindow"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="ScrollViewWindow"
Width="800"
Height="350"
mc:Ignorable="d"
>
<Window.Resources>
<Style x:Key="tbk.Base"
TargetType="TextBlock"
>
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0,12,20,12" />
</Style>
<Style x:Key="tbx.Base"
TargetType="TextBox"
>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0,12,60,12" />
</Style>
<Style x:Key="Btn.Base"
TargetType="Button"
>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Padding" Value="0" />
<Setter Property="Background" Value="DarkGreen" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Margin" Value="20,0,0,0" />
<Setter Property="Height" Value="36" />
<Setter Property="Width" Value="90" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition x:Name="ScrollRow" MaxHeight="{Binding ElementName=MyForm, Path=ActualHeight}" />
<RowDefinition x:Name="ButtonsRow" Height="80" />
<RowDefinition x:Name="SpaceRow" Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer x:Name="MyScroll"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
>
<Grid x:Name="MyForm"
Background="Moccasin"
>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="160" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Grid.Row="0"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="0"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="1"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="1"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="2"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="2"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="3"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="3"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="4"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="4"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="5"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="5"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="6"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="6"
Style="{StaticResource tbx.Base}"
/>
<TextBlock
Grid.Column="0"
Grid.Row="7"
Text="INDEX"
Style="{StaticResource tbk.Base}"
/>
<TextBox
Grid.Column="1"
Grid.Row="7"
Style="{StaticResource tbx.Base}"
/>
</Grid>
</ScrollViewer>
<StackPanel
Grid.Row="1"
HorizontalAlignment="Center"
Orientation="Horizontal"
>
<Button
Content="Cancel"
Margin="0"
Style="{StaticResource Btn.Base}"
/>
<Button
Content="Save"
Style="{StaticResource Btn.Base}"
/>
</StackPanel>
</Grid>
</Window>

Set TextBlock width to 100% inside DataTemplate in Windows Store app

I have this XAML and having problems with grid width.
<DataTemplate x:Key="FormTileItemTemplate">
<Grid Height="70" Background="#FFECECEC">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="38" />
</Grid.ColumnDefinitions>
<StackPanel Margin="10,0,20,15" VerticalAlignment="Bottom">
<TextBlock Text="{Binding FormName}" Foreground="Black" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="0" FontSize="34.667" FontWeight="Light" LineHeight="32" />
</StackPanel>
<Grid Grid.Column="1">
<Image Stretch="UniformToFill" Source="/Assets/Images/FormCompleteRed.png" />
</Grid>
</Grid>
</DataTemplate>
<Grid x:Name="itemFormsGrid" Margin="0,60,0,50">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0,0,20,0" Width="100" Height="100" Source="/Assets/Images/session-forms.png" Stretch="UniformToFill" HorizontalAlignment="Right" />
<ListView
x:Name="formListView"
Grid.Row="1"
IsSwipeEnabled="False"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource FormTileItemTemplate}"
d:DataContext="{Binding Path=SessionForms, Source={d:DesignInstance Type=SampleData:SessionReviewDesignDataSource, IsDesignTimeCreatable=True} }"
Margin="0,20,0,0" />
</Grid>
Here is the output. Output
But I need the TextBlock to stretch way up to right. Appreciate any help.
Set HorizontalContentAlignment property like below to stretch the ListViewItems
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>

User control inside ScrollViewer doesn't scroll in WPF

I have the following code (abbreviated) in my main window:
Although I set both scroll bar visibilities and CanContentScroll properties it doesn't scroll. I assume it has to do with my user control.
<Window>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TabControl Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Height="Auto" Width="Auto">
<TabItem Header="TEST">
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<my:MY_USER_CONTROL x:Name="myUserControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.CanContentScroll="True" />
</ScrollViewer>
</TabItem>
</TabControl>
<Button Grid.Column="0" Grid.Row="2" >a button</Button>
<WrapPanel Grid.Column="0" Grid.Row="3" >
</WrapPanel>
</Grid>
</Window>
Abbreviated structure of my user control:
<UserControl>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="183*" />
<ColumnDefinition Width="117*" />
</Grid.ColumnDefinitions>
<TreeView ItemsSource="{Binding Children}" Grid.ColumnSpan="2">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.Children>
<TextBlock Background="LightGray" Padding="2" Margin="2" Grid.Row="0" Grid.Column="0" Text="{Binding Name}" />
<TextBlock Padding="2" Margin="2" Grid.Row="0" Grid.Column="1" Text="{Binding Content}" />
</Grid.Children>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</UserControl>
You need to set it like this. I changed the RowDefinition for Row0 to Height="*" So it will use as much space it can. Then changed place between the ScrollViewer and the TabControl. So the TabControl is a content of the ScrollViewer.
<Window>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
Grid.Column="0" Grid.Row="0">
<TabControl HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch"
Height="Auto" Width="Auto">
<TabItem Header="TEST">
<my:MY_USER_CONTROL x:Name="myUserControl"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ScrollViewer.CanContentScroll="True" />
</TabItem>
</TabControl>
</ScrollViewer>
<Button Grid.Column="0" Grid.Row="2" >a button</Button>
<WrapPanel Grid.Column="0" Grid.Row="3" >
</WrapPanel>
</Grid>
When you set CanContentScroll to True, the ScrollViewer assumes that your content implements IScrollInfo (which i guess doesn´t).
Try setting CanContentScroll on the ScrollViewer to false, this allows the content to use as much space as it wants and the ScrollViewer takes care of scrolling.
However, depending on the size, number of visuals etc. of your control, this might become a performance issue (e.g. no UI Virtualization when CanContentScroll is set to False).
Looks like the content inside your scrollviewer is the same size as the viewer so there is nothing to scroll?
if you do something like
<ScrollViewer HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<Grid Background="Red">
</Grid>
</ScrollViewer>
Then the grid is the same size as the scroll viewer and will never allow scrolling, if you set the height of the grid to more than the viewer can display you'll get a scroller.
<ScrollViewer HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<Grid Background="Red" Height="500">
</Grid>
</ScrollViewer>

LabeledPieChart: Style overrides DataTemplate

I have customized the template of LabeledPieChart (source: Bea) in a Style. Then I created a DataTemplate for the Slices of the LabeledPieChart. Both the style and the DataTemplate works great if they are alone. If they are together the Style overrides the DataTemplate that he has no effect. Is it possible to combine these two?
Here is my Code (The Style and the DataTemplate are in Window.Resources):
Style:
<Style TargetType="customControls:LabeledPieChart" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="customControls:LabeledPieChart">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15*" />
<ColumnDefinition Width="9*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<dataVis:Title Content="{TemplateBinding Title}" Style="{TemplateBinding TitleStyle}" Margin="0,5,0,3"/>
<Grid Grid.Row="1" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<chartPrmtvs:EdgePanel x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}">
<Grid Canvas.ZIndex="-1" Background="Transparent" />
<Border Canvas.ZIndex="10" BorderBrush="#FF919191" BorderThickness="0" />
</chartPrmtvs:EdgePanel>
</Grid>
</Grid>
<dataVis:Legend x:Name="Legend" Style="{TemplateBinding LegendStyle}" Title="{TemplateBinding LegendTitle}"
BorderThickness="0" Background="Transparent" FontSize="15" Grid.Column="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
DataTemplate:
<DataTemplate DataType="{x:Type local:City}" >
<Border BorderThickness="1" BorderBrush="Gray">
<StackPanel Background="White" Orientation="Horizontal">
<TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type customControls:PieChartLabel}}, Path=FormattedRatio}" VerticalAlignment="Center" Margin="5,0,5,0" />
<TextBlock Text="- " />
<TextBlock Text="{Binding Path=Population}" Margin="5,0,5,0" />
<TextBlock Text="- " />
<TextBlock Text="{Binding Name}" Margin="0,0,5,0"/>
</StackPanel>
</Border>
</DataTemplate>
LabeldPieChart:
<Grid>
<customControls:LabeledPieChart
x:Name="labeledPieChart"
Title="Population of Puget Sound Cities"
Height="500" Width="700"
Grid.Row="3"
BorderBrush="Gray"
>
<customControls:LabeledPieChart.Series>
<customControls:LabeledPieSeries
x:Name="labeledPieSeries"
ItemsSource="{Binding}"
IndependentValuePath="Name"
DependentValuePath="Population"
IsSelectionEnabled="True"
LabelDisplayMode="Auto"
/>
</customControls:LabeledPieChart.Series>
</customControls:LabeledPieChart>
</Grid>

Style each datagrid column header

I want to add another row to the HeaderRow and for each column insert specific control.
This is my code where add this row, but I can only set same control (in this case textbox) for every column, but I want to set specific control for specific column.
(like it's done in ASP.NET repeater)
<Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid x:Name="grid" VerticalAlignment="Center" HorizontalAlignment="Stretch" Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Name="ColumnHeader" Grid.Row="0" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" Height="18" />
<Grid Grid.Row="1">
<TextBox Text="" HorizontalAlignment="Stretch" BorderThickness="0,1,1,1" />
</Grid>
</Grid>
</Style>
You can Make use of the HeaderTemplate to specify different datatemplates for each Column
Sample
<Window.Resources>
<DataTemplate x:Key="Template1">
<Grid x:Name="grid" VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Name="ColumnHeader" Text="Student Id" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="18" />
<Grid Grid.Row="1">
<TextBox Text="" HorizontalAlignment="Stretch" BorderThickness="0,1,1,1" />
</Grid>
</Grid>
</DataTemplate>
<DataTemplate x:Key="Template2">
<Grid x:Name="grid" VerticalAlignment="Center" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Name="ColumnHeader" Text="Student Name" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="18" />
<Grid Grid.Row="1">
<TextBox Text="" HorizontalAlignment="Stretch" BorderThickness="0,1,1,1" />
</Grid>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<DataGrid Name="dataGrid" >
<DataGrid.Columns>
<DataGridTextColumn HeaderTemplate="{StaticResource Template1}" Width="90*" MinWidth="120" Binding="{Binding StudentId}"/>
<DataGridTextColumn HeaderTemplate="{StaticResource Template2}" Width="90*" MinWidth="120" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Score" Width="100*" MinWidth="150" Binding="{Binding Score}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
I approached this a little bit different, I styled DataGridColumnHeadersPresenter, it allows me to syle the column headers row (instead of column header).
There I add my new row and all the controls I need, I alsoe set the width of every cell to match the width of it's header .
<Style x:Key="DataGridColumnHeadersPresenterStyle1" TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeadersPresenter}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DataGridColumnHeader x:Name="PART_FillerColumnHeader" IsHitTestVisible="False"/>
<ItemsPresenter/>
<Grid Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Left" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding ActualWidth, ElementName=Col1}"/>
<ColumnDefinition Width="{Binding ActualWidth, ElementName=Col2}"/>
<ColumnDefinition Width="{Binding ActualWidth, ElementName=Col3}"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Bottom" Width="Auto" Height="25" BorderThickness="1,2,0,2"/>
my other controls go here
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>

Resources