0

I am not able to move buttons inside of a dock panel to the right, I tried few solutions, and after all I put them in stack panels and tried to move them to the right, but acctualy they wont move anywhere, here is how it looks:enter image description here

And here is my code:

   <GroupStyle>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander IsExpanded="True"  Background="Black" Opacity="0.7">
                                    <Expander.Header>
                                        <DockPanel Height="50">
                                          <StackPanel Orientation="Horizontal" VerticalAlignment="Center" DockPanel.Dock="Right"> <Button DockPanel.Dock="Right" Content="Test" Margin="0,0,28,0"/></StackPanel>    
                                          <StackPanel Orientation="Horizontal" VerticalAlignment="Center" DockPanel.Dock="Left">  <TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Order Number:# {0}}" /></StackPanel>
                                        </DockPanel>
                                    </Expander.Header>
                                    <Expander.Content>
                                        <ItemsPresenter />
                                    </Expander.Content>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </DataGrid.GroupStyle>

edit:

enter image description here

This above causes width on dock panel

<DockPanel Height="50" Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}">
                                        <Button DockPanel.Dock="Right" Content="Test" Margin="0,0,28,0"/>
                                        <TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Order Number:# {0}}" />
                                    </DockPanel>
Roxy'Pro
  • 4,216
  • 9
  • 40
  • 102
  • it is likely `Expander` aligning Header content to the left side. if you need to change that, you may try suggestiongs from here: http://stackoverflow.com/questions/680498/how-can-i-make-a-wpf-expander-stretch – ASh Sep 29 '16 at 09:22
  • If I add `Width={Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}">` to my DockPanel than I am having problem, my vertical slider wont work anymore, so I had to use mouse scroll to get bottom of my dataGrid, I allready tried this – Roxy'Pro Sep 29 '16 at 09:26

2 Answers2

0

Apply Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}" to your DockPanel and see if this solves your problem.

AnjumSKhan
  • 9,647
  • 1
  • 26
  • 38
  • you mean like this: ` ` if so, than Its showing me Just in time debugger. An unhandled Microsoft .NET Framework exception, which means something is not ok :) – Roxy'Pro Sep 29 '16 at 10:04
  • @Roxy'Pro Sorry its DockPanel and not Expander. – AnjumSKhan Sep 29 '16 at 10:31
  • I made edit on my post, that causes expanding of my window, so my MainWindow is not anymore on width 100% of my screen, it breaks screen and goes little bit right so I have to use horizontal slider to see all of my content ( in this case buttons) – Roxy'Pro Sep 29 '16 at 11:48
  • `AncestorType=DataGrid` is OK, because vertical slider works also for me also with that solution, probably it width is not ok so it expand my main window which is not good, how could we reduce it's width? – Roxy'Pro Sep 29 '16 at 12:52
0

Try the following method. this works in my project

<DockPanel Height="50">
   <grid DockPanel.Dock="Right">
       <Button  Content="Test" Margin="0,0,28,0"/>
   </grid >    
   <grid DockPanel.Dock="Left">
       <TextBlock FontWeight="Normal" FontFamily="Verdana" FontSize="20" Height="25" Foreground="#83D744" Text="{Binding Path=Name,StringFormat= Order Number:# {0}}"/>
   </grid>
</DockPanel>            
Siby Sunny
  • 714
  • 6
  • 14