【问题标题】:Wpf Dock Panel Dock left and Dock rightWpf Dock 面板 Dock left 和 Dock right
【发布时间】: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}"&gt; 添加到我的 DockPanel 而不是我遇到问题,我的垂直滑块将不再工作,所以我不得不使用鼠标滚动来获取我的 dataGrid 的底部,我已经尝试过这个跨度>

标签: wpf datagrid alignment grouping dock


【解决方案1】:

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

【讨论】:

  • 你的意思是这样的:&lt;Expander IsExpanded="True" Background="Black" Opacity="0.7" Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"&gt; 如果是这样,那么它会向我显示即时调试器。未处理的 Microsoft .NET Framework 异常,这意味着某些事情不正常 :)
  • @Roxy'Pro 对不起它的 DockPanel 而不是 Expander。
  • 我在我的帖子上进行了编辑,这导致我的窗口扩大,所以我的 MainWindow 不再是我屏幕的 100% 宽度,它打破了屏幕并且有点正确,所以我必须使用水平滑块查看我的所有内容(在本例中为按钮)
  • AncestorType=DataGrid 没问题,因为垂直滑块也适用于我的解决方案,可能它的宽度不合适,所以它扩展了我的主窗口,这不好,我们怎么能减少它的宽度?
【解决方案2】:

试试下面的方法。这适用于我的项目

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

【讨论】:

    猜你喜欢
    • 2017-02-11
    • 2015-12-18
    • 2023-04-05
    • 2011-07-24
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    相关资源
    最近更新 更多