【发布时间】:2017-02-07 12:39:46
【问题描述】:
我无法将停靠面板内的按钮向右移动,我尝试了几种解决方案,毕竟我将它们放在堆栈面板中并尝试将它们向右移动,但实际上它们不会移动到任何地方,在这里是怎么看的:
这是我的代码:
<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>
编辑:
上面这会导致停靠面板上的宽度
<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>
【问题讨论】:
-
很可能
Expander将标题内容与左侧对齐。如果你需要改变它,你可以从这里尝试建议:stackoverflow.com/questions/680498/… -
如果我将
Width={Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}">添加到我的 DockPanel 而不是我遇到问题,我的垂直滑块将不再工作,所以我不得不使用鼠标滚动来获取我的 dataGrid 的底部,我已经尝试过这个跨度>
标签: wpf datagrid alignment grouping dock