保持 UWP 标题栏中的菜单可拖动和可调整大小

Keep menu in UWP title bar draggable and resizable

我正在尝试使用 Uno 制作一个跨平台应用程序,专门用于桌面,我想调整 UWP 构建以在标题栏中放置一个菜单 - 我可以做到。

我不能做的是使 window 始终保持可调整大小并可拖动到标题栏中的菜单外。

我尝试了多种方法,其中 none 似乎有效 我得到的工作菜单没有 resize/drag 或 resizable/draggable window non-functional 菜单。

这是我目前所拥有的

在 App.xaml.cs->OnLaunched 的底部:

#if WINDOWS_UWP
      CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
      ApplicationView appView = ApplicationView.GetForCurrentView();
      appView.TitleBar.BackgroundColor = Colors.Transparent;
      appView.TitleBar.ButtonBackgroundColor = Colors.Transparent;
      appView.TitleBar.ButtonForegroundColor = Colors.DarkGray;
      appView.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
      appView.TitleBar.InactiveBackgroundColor = Colors.Transparent;
#endif

在MainPage.xaml.cs中:

public MainPage()
{
  this.InitializeComponent();
  Window.Current.SetTitleBar(bkgTitleBar);
}

以及MainPage.xaml的内容:

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" x:Name="ctlTitleBar" Background="Transparent">
            <Rectangle x:Name="bkgTitleBar" />
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Background="Transparent">
                    <!--<Rectangle x:Name="bkgTitleBar" />-->
                    <MenuBar>
                        <MenuBarItem Title="File">
                            <MenuFlyoutSubItem Text="New">
                                <MenuFlyoutItem Text="Plain Text Document"/>
                                <MenuFlyoutItem Text="Rich Text Document"/>
                                <MenuFlyoutItem Text="Other Formats..."/>
                            </MenuFlyoutSubItem>
                            <MenuFlyoutItem Text="Open..."/>
                            <MenuFlyoutItem Text="Save"/>
                            <MenuFlyoutSeparator />
                            <MenuFlyoutItem Text="Exit"/>
                        </MenuBarItem>

                        <MenuBarItem Title="Edit">
                            <MenuFlyoutItem Text="Undo"/>
                            <MenuFlyoutItem Text="Cut"/>
                            <MenuFlyoutItem Text="Copy"/>
                            <MenuFlyoutItem Text="Paste"/>
                        </MenuBarItem>

                        <MenuBarItem Title="View">
                            <MenuFlyoutItem Text="Output"/>
                            <MenuFlyoutItem Text="Raw"/>
                            <MenuFlyoutSeparator/>
                            <MenuFlyoutItem Text="External..."/>
                        </MenuBarItem>

                        <MenuBarItem Title="Help">
                            <MenuFlyoutItem Text="About"/>
                        </MenuBarItem>
                    </MenuBar>
                </Grid>
            </Grid>
        </Grid>

        <Grid Grid.Row="1" VerticalAlignment="Top">
            <Viewbox>
                <Grid MinWidth="1680">
                    <TextBlock Text="Oobey! Doobey! Doobey! Dooo!" Margin="20" FontSize="30" FontFamily="{StaticResource TextBlockFontFamily1}" />
                    <ToggleButton Content="clicky" FontWeight="Bold"  Margin="86,120,0,0" VerticalAlignment="Top" Height="59" Width="233" FontSize="22" />
                    <ToggleButton Content="clicky2" FontWeight="Bold"  Margin="1519,276,0,0" VerticalAlignment="Top" Height="59" Width="233" FontSize="22"/>
                </Grid>
            </Viewbox>
        </Grid>
    </Grid>
</Page>

理想情况下,当“OneDrive”按钮出现在顶部时,我希望能够像 Windows 照片应用程序那样工作。

谁能帮我做这个?

您需要确保设置为“标题栏”的元素具有 non-zero 尺寸并覆盖您希望拖动的区域。在这种情况下,bkgTitleBar 默认没有尺寸和背景,所以请尝试给它一个尺寸:

<Rectangle 
   x:Name="bkgTitleBar" 
   Fill="Transparent" 
   HorizontalAlignment="Stretch" 
   VerticalAlignment="Stretch" />

这应该拉伸 Rectangle 以匹配 ctlTitleBar 的大小。