2016-09-29 131 views
0

我无法将按钮面板内的按钮移动到右边,我尝试了几个解决方案,毕竟我把它们放在堆叠面板上并试图将它们移动到右边,但acctualy他们不会移动任何地方,这里是它的外观:enter image description hereWpf Dock Dock左边和Dock右边

这里是我的代码:

<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> 

编辑:

enter image description here

这上面的原因宽度固定面板上

<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> 
+0

它很可能是'Expander'将标题内容对齐到左侧。如果你需要改变它,你可以尝试从这里建议:http://stackoverflow.com/questions/680498/how-can-i-make-a-wpf-expander-stretch – ASh

+0

如果我添加'宽度= {绑定 \t \t \t \t \t \t \t \t的RelativeSource = {的RelativeSource \t \t \t \t \t \t模式= FindAncestor, \t \t \t \t \t \t \t AncestorType = {X:式膨胀}}, \t \t \t \t \t \t \t \t路径= ActualWidth的}“>'我DockPanel中比我有问题,我的垂直滑块不会工作了,所以我不得不用鼠标滚动,让我的数据网格的底部,我媒体链接尝试这个 –

回答

0

应用Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"DockPanel,看看是否能解决您的问题。

+0

你的意思是这样的:'> if if,比它展示给我的只是及时的调试器。一个未处理的Microsoft .NET框架异常,这意味着什么不好:) –

+0

@ Roxy'Pro对不起它的DockPanel而不是扩展器。 – AnjumSKhan

+0

我在我的帖子上做了编辑,导致我的窗口扩大,所以我的MainWindow不再是我的屏幕宽度的100%,它打破了屏幕,并有点偏右,所以我必须使用水平滑块来查看我的所有内容(在这种情况下,按钮) –

0

请尝试以下方法。这在我的项目中有效

<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>    
+0

它不适合我 –