2016-09-29 193 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

它不適合我 –