How to add button at the right corner of Expander - WPF DataGrid
<p>I would like to know how to put button to the right part of my expander, here is picture of how does it look when my expander is collapsed (I need buttons no matter is it expanded or not).</p>

<p><a href="https://i.stack.imgur.com/7N8ve.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7N8ve.png" alt="enter image description here"></a></p>

<p>I need to get this, so when user click on button I must get ID of order and do some action!
<a href="https://i.stack.imgur.com/1xJSE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1xJSE.png" alt="enter image description here"></a></p>

<p>Here is my code:</p>

<pre><code>&lt;Grid&gt;
    &lt;Grid.ColumnDefinitions&gt;
        &lt;ColumnDefinition Width="10*" /&gt;
    &lt;/Grid.ColumnDefinitions&gt;

    &lt;DataGrid IsSynchronizedWithCurrentItem="False" Grid.Column="0" VerticalGridLinesBrush="Transparent"  RowHeaderWidth="0" CanUserAddRows="False" AutoGenerateColumns="False"  x:Name="datagrid1" Margin="10,150,8,50" Background="Transparent" RowBackground="#FF494949"  VerticalContentAlignment="Center" HorizontalContentAlignment="Center" ItemsSource="{Binding}"&gt;
        &lt;DataGrid.Resources&gt;
            &lt;Style TargetType="{x:Type DataGridColumnHeader}"&gt;
                &lt;Setter Property="Background" Value="Black"/&gt;
                &lt;Setter Property="Opacity" Value="0.5"/&gt;
                &lt;Setter Property="Foreground" Value="White"/&gt;
                &lt;Setter Property="HorizontalContentAlignment" Value="Center" /&gt;
                &lt;Setter Property="FontSize" Value="15"/&gt;
                &lt;Setter Property="FontFamily" Value="Arial"/&gt;
                &lt;Setter Property="Height" Value="50"/&gt;
            &lt;/Style&gt;


    &lt;Style x:Key="TextInCellCenter" TargetType="{x:Type TextBlock}" &gt;
        &lt;Setter Property="TextAlignment" Value="Center"/&gt;
    &lt;/Style&gt;

    &lt;Style TargetType="{x:Type TextBlock}" x:Key="RightAligElementStyle"&gt;
        &lt;Setter Property="TextAlignment" Value="Right"/&gt;
    &lt;/Style&gt;

    &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#83D744"/&gt;

    &lt;/DataGrid.Resources&gt;

        &lt;DataGrid.Columns&gt;
            &lt;DataGridTextColumn Binding="{Binding Title}"       Header="Product Name"   Width="0.25*"   Foreground="White" FontSize="20"  FontFamily="Verdana" /&gt;
            &lt;DataGridTextColumn Binding="{Binding Quantity}"    ElementStyle="{StaticResource TextInCellCenter}"     Header="Quantity"    Foreground="White"     Width="0.15*"       FontSize="20" FontFamily="Verdana" /&gt;
            &lt;DataGridTextColumn Binding="{Binding User}"        ElementStyle="{StaticResource TextInCellCenter}"     Header="User"        Foreground="White"     Width="0.20*"       FontSize="20" FontFamily="Verdana" /&gt;
        &lt;/DataGrid.Columns&gt;

    &lt;DataGrid.GroupStyle&gt;
        &lt;!-- Style for groups at top level. --&gt;
        &lt;GroupStyle&gt;
            &lt;GroupStyle.ContainerStyle&gt;
                &lt;Style TargetType="{x:Type GroupItem}"&gt;
                    &lt;Setter Property="Template"&gt;
                        &lt;Setter.Value&gt;
                            &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                &lt;Expander IsExpanded="True"  Background="#83D744"&gt;
                                    &lt;Expander.Header&gt;
                                        &lt;DockPanel Height="50"&gt;
                                            &lt;TextBlock FontWeight="Bold" FontSize="20" Height="25"  Foreground="Black" Text="{Binding Path=Name,StringFormat= OrderNumber:# {0}}" /&gt;
                                        &lt;/DockPanel&gt;
                                    &lt;/Expander.Header&gt;
                                    &lt;Expander.Content&gt;
                                        &lt;ItemsPresenter /&gt;
                                    &lt;/Expander.Content&gt;
                                &lt;/Expander&gt;
                            &lt;/ControlTemplate&gt;
                        &lt;/Setter.Value&gt;
                    &lt;/Setter&gt;
                &lt;/Style&gt;
            &lt;/GroupStyle.ContainerStyle&gt;
        &lt;/GroupStyle&gt;
    &lt;/DataGrid.GroupStyle&gt;
&lt;/DataGrid&gt;
</code></pre>

<p>Thanks guys,
Cheers</p>

<p>After Joe's answer I achieved this, but how come there is no button on last item in a DataGrid, take a look at this screenshot:
<a href="https://i.stack.imgur.com/dLpox.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dLpox.png" alt="enter image description here"></a></p>

<p>CODE:</p>

<pre><code>&lt;Grid&gt;
&lt;Grid.ColumnDefinitions&gt;
    &lt;ColumnDefinition Width="10*" /&gt;
&lt;/Grid.ColumnDefinitions&gt;

&lt;DataGrid IsSynchronizedWithCurrentItem="False" Grid.Column="0" VerticalGridLinesBrush="Transparent"  RowHeaderWidth="0" CanUserAddRows="False" AutoGenerateColumns="False"  x:Name="datagrid1" Margin="10,150,8,50" Background="Transparent" RowBackground="#FF494949"  VerticalContentAlignment="Center" HorizontalContentAlignment="Center" ItemsSource="{Binding}"&gt;
    &lt;DataGrid.Resources&gt;
        &lt;Style TargetType="{x:Type DataGridColumnHeader}"&gt;
            &lt;Setter Property="Background" Value="Black"/&gt;
            &lt;Setter Property="Opacity" Value="0.5"/&gt;
            &lt;Setter Property="Foreground" Value="White"/&gt;
            &lt;Setter Property="HorizontalContentAlignment" Value="Center" /&gt;
            &lt;Setter Property="FontSize" Value="15"/&gt;
            &lt;Setter Property="FontFamily" Value="Arial"/&gt;
            &lt;Setter Property="Height" Value="50"/&gt;
        &lt;/Style&gt;


&lt;Style x:Key="TextInCellCenter" TargetType="{x:Type TextBlock}" &gt;
    &lt;Setter Property="TextAlignment" Value="Center"/&gt;
&lt;/Style&gt;

&lt;Style TargetType="{x:Type TextBlock}" x:Key="RightAligElementStyle"&gt;
    &lt;Setter Property="TextAlignment" Value="Right"/&gt;
&lt;/Style&gt;

&lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#83D744"/&gt;

&lt;/DataGrid.Resources&gt;

    &lt;DataGrid.Columns&gt;
        &lt;DataGridTextColumn Binding="{Binding Title}"       Header="Product Name"   Width="0.25*"   Foreground="White" FontSize="20"  FontFamily="Verdana" /&gt;
        &lt;DataGridTextColumn Binding="{Binding Quantity}"    ElementStyle="{StaticResource TextInCellCenter}"     Header="Quantity"    Foreground="White"     Width="0.15*"       FontSize="20" FontFamily="Verdana" /&gt;
        &lt;DataGridTextColumn Binding="{Binding User}"        ElementStyle="{StaticResource TextInCellCenter}"     Header="User"        Foreground="White"     Width="0.20*"       FontSize="20" FontFamily="Verdana" /&gt;
    &lt;/DataGrid.Columns&gt;



    &lt;DataGrid.GroupStyle&gt;
        &lt;!-- Style for groups at top level. --&gt;
        &lt;GroupStyle&gt;
            &lt;GroupStyle.ContainerStyle&gt;
                &lt;Style TargetType="{x:Type GroupItem}"&gt;
                    &lt;Setter Property="Template"&gt;
                        &lt;Setter.Value&gt;
                            &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                &lt;Expander IsExpanded="True"  Background="Black" Opacity="0.7"&gt;
                                    &lt;Expander.Header&gt;
                                        &lt;DockPanel Height="50" Width="{Binding
                                                          RelativeSource={RelativeSource
                                                          Mode=FindAncestor,
                                                          AncestorType={x:Type Expander}},
                                                          Path=ActualWidth}"&gt;
                                            &lt;Button DockPanel.Dock="Right" Content="Test Button" Margin="0,0,28,0"/&gt;
                                            &lt;TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Order Number:# {0}}" /&gt;
                                        &lt;/DockPanel&gt;
                                    &lt;/Expander.Header&gt;
                                    &lt;Expander.Content&gt;
                                        &lt;ItemsPresenter /&gt;
                                    &lt;/Expander.Content&gt;
                                &lt;/Expander&gt;
                            &lt;/ControlTemplate&gt;
                        &lt;/Setter.Value&gt;
                    &lt;/Setter&gt;
                &lt;/Style&gt;
            &lt;/GroupStyle.ContainerStyle&gt;
        &lt;/GroupStyle&gt;
    &lt;/DataGrid.GroupStyle&gt;
&lt;/DataGrid&gt;
</code></pre>

<p>So for strange reason <strong>button on last item is not visible</strong>...</p>