如何根据wpf工具栏托盘的可用空间调整宽度

发布于 2024-12-21 03:54:41 字数 1343 浏览 0 评论 0原文

我在 WPF ToolbarTray 控件内使用大约 10-15 个控件,现在的问题是,当我更改分辨率时,其中存在的控件在最大化窗口的情况下不会根据我的需要进行调整。有关更多详细信息,我附上了下面的屏幕截图。

最初出现的工具栏托盘控件: 最初出现的工具栏托盘控件

工具栏托盘需要像这样显示(我正在尝试): 工具栏托盘需要像这样出现

谁能告诉我如何自定义或如何实现像 ToolbarTray 这样的第二个图像。任何帮助表示赞赏。

提前致谢,

更新:

<ToolBarTray Background="White">
    <ToolBar>

        <Button
        Width="50" Content="hi"/>
        <Button
        Width="100" Content="bye"/>
        <Button
        Content="welcome"/>
        <Button
        Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button
        ToolBar.OverflowMode="Always" Content="save" />
        <Button
        ToolBar.OverflowMode="Always" Content="open" />
        <Button
        ToolBar.OverflowMode="AsNeeded" Content="bmp" />
    </ToolBar>
    <ToolBar HorizontalAlignment="Right">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="New Hi1"/>
            <Button Content="New Hi2"/>
            <Button Content="New Hi3"/>
        </StackPanel>
    </ToolBar>
</ToolBarTray>

I am using around 10-15 controls inside a WPF ToolbarTray control, Now the issue is while I am changing the resolution the controls present in it is not adjusting according to my need in case of Maximized window. For more detail I attached the screenshot below.

Toolbar Tray control appearing originally:
Toolbar Tray control appearing originally

Toolbar Tray need to appear like this(Which I am trying):
Toolbar Tray need to appear like this

Can anybody tell me how to customize or what to do to achieve the second image like ToolbarTray.Any help is appreciated.

Thanks in advance,

Update:

<ToolBarTray Background="White">
    <ToolBar>

        <Button
        Width="50" Content="hi"/>
        <Button
        Width="100" Content="bye"/>
        <Button
        Content="welcome"/>
        <Button
        Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button
        ToolBar.OverflowMode="Always" Content="save" />
        <Button
        ToolBar.OverflowMode="Always" Content="open" />
        <Button
        ToolBar.OverflowMode="AsNeeded" Content="bmp" />
    </ToolBar>
    <ToolBar HorizontalAlignment="Right">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="New Hi1"/>
            <Button Content="New Hi2"/>
            <Button Content="New Hi3"/>
        </StackPanel>
    </ToolBar>
</ToolBarTray>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风追烟花雨 2024-12-28 03:54:41

据我所知,这是不可能的,因为 ToolbarTray 的布局选项非常有限。

您可以做的是将工具栏包装在 DockPanel 中以进行布局。但是您错过了一些事情,例如通过拖放更改工具栏位置。

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
      <DockPanel Grid.Row="0" Background="White">
        <ToolBar DockPanel.Dock="Left">
         ....
      </ToolBar>
      <ToolBar DockPanel.Dock="Right" HorizontalAlignment="Right" HorizontalContentAlignment="Stretch">
        ...
      </ToolBar>
    </DockPanel>

As far as I know this is not possible out of the box, as the ToolbarTray is quite limited in its layout options.

What you could do is wrap the Toolbars in a DockPanel to do the layouting. But you are missing things then like changing toolbar positions via drag and drop.

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="50"></RowDefinition>
      <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
      <DockPanel Grid.Row="0" Background="White">
        <ToolBar DockPanel.Dock="Left">
         ....
      </ToolBar>
      <ToolBar DockPanel.Dock="Right" HorizontalAlignment="Right" HorizontalContentAlignment="Stretch">
        ...
      </ToolBar>
    </DockPanel>
扮仙女 2024-12-28 03:54:41

我找到了问题的解决方案,现在我在 ToolBar 控件内使用网格并调整网格(toolbarGrid)一列的大小以使我的控件如第二个图像中所示。

代码:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="0"/>
    <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

<Stackpanel
    Grid.Column ="0">

    <Button Width="50" Content="hi"/>
        <Button Width="100" Content="bye"/>
        <Button Content="welcome"/>
        <Button Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button ToolBar.OverflowMode="Always" Content="save" />
        <Button ToolBar.OverflowMode="Always" Content="open" />
        <Button ToolBar.OverflowMode="AsNeeded" Content="bmp" />
</StackPanel>

    <ToolBarTray x:Name ="toolBarTray" Grid.Column ="1" HorizontalAlignment ="Right" IsLocked="True">

        <!--First Toolbar for the controls from Print to Zoom Control-->
        <ToolBar x:Name ="topToolBar" FocusVisualStyle="{x:Null}">
            <Grid x:Name="toolbarGrid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Content="New Hi1"/>
                <Button Content="New Hi2"/>
                <Button Content="New Hi3"/>
            </Grid>
        </ToolBar>
    </ToolBarTray>
</Grid>

I found the solution of my problem, now I am using a Grid inside the ToolBar control and adjusting the size of one column of the Grid(toolbarGrid) to make my controls as seen in my second Image.

Code:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="0"/>
    <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>

<Stackpanel
    Grid.Column ="0">

    <Button Width="50" Content="hi"/>
        <Button Width="100" Content="bye"/>
        <Button Content="welcome"/>
        <Button Width="20"/>
        <Button Content="Welcome"/>
        <Separator />
        <Button ToolBar.OverflowMode="Always" Content="save" />
        <Button ToolBar.OverflowMode="Always" Content="open" />
        <Button ToolBar.OverflowMode="AsNeeded" Content="bmp" />
</StackPanel>

    <ToolBarTray x:Name ="toolBarTray" Grid.Column ="1" HorizontalAlignment ="Right" IsLocked="True">

        <!--First Toolbar for the controls from Print to Zoom Control-->
        <ToolBar x:Name ="topToolBar" FocusVisualStyle="{x:Null}">
            <Grid x:Name="toolbarGrid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Content="New Hi1"/>
                <Button Content="New Hi2"/>
                <Button Content="New Hi3"/>
            </Grid>
        </ToolBar>
    </ToolBarTray>
</Grid>
℉絮湮 2024-12-28 03:54:41

简单的答案不是在应用程序的顶部“行”中绘制灰色背景?

The simple answer wouldn't be to draw a grey background in the top 'line' of your App ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文