【问题标题】:How can I get an app bar to stay at the bottom regardless of screen resolution?无论屏幕分辨率如何,如何让应用栏保持在底部?
【发布时间】:2013-09-27 23:15:10
【问题描述】:

我正在用 c# 构建一个 Windows 8 应用程序,但我无法让应用程序栏停留在屏幕底部。

我正在 2560x1440 的 PC 显示器和 1366x768 的 Windows 表面上测试该程序。它非常适合(默认情况下)Windows Surface 设备,但会显示在 PC 显示器的屏幕中间。

这是我所拥有的:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
     can.Height = user.screenHeight; //Can is a canvas, which is being drawn on to. 
     can.Width = user.screenWidth; //user class contains information about the current user of the program

     var resScale = Windows.Graphics.Display.DisplayProperties.ResolutionScale;           
}

我可以轻松设置画布,因为它覆盖了整个屏幕。但我不确定如何接近应用栏。我很惊讶没有一个属性会自动将栏标记到屏幕底部。

这是应用栏的 XAML:

<AppBar x:Name="mainBar" Canvas.Top="700" Width="1366" VerticalAlignment="Bottom">
    <Button Style="{StaticResource NewWindowAppBarButtonStyle}" Click="Button_Click_1" />
</AppBar>

抱歉,如果有人问过这个问题。只是我一直在四处寻找,找不到任何可以帮助我的东西。

谢谢

【问题讨论】:

  • Canvas 不是用于布局 UI 元素的合适容器。使用GridDockPanel 之类的
  • 将画布放入网格中?我正在使用画布,因为我的程序需要绘制到窗口。
  • 您将AppBar 放在画布内,这是错误的。使用 Grid 或其他一些用于布局的容器。

标签: c# xaml windows-8 microsoft-metro


【解决方案1】:

你为什么不试试这个。无论屏幕分辨率如何,这都会在页面底部打开应用栏。

<Page.BottomAppBar>
    <AppBar x:Name="mainBar" Padding="10,0,10,0" AutomationProperties.Name="Bottom App Bar" IsOpen="True">
         <Button Style="{StaticResource NewWindowAppBarButtonStyle}" Click="Button_Click_1" />
    </AppBar>
</Page.BottomAppBar>

【讨论】:

    【解决方案2】:

    如果画布是必需的,那么你可以使用它来设置宽度和高度

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var bounds = Window.Current.Bounds;
        can.Height = bounds.Height;
        can.Width = bounds.Width;
    }
    

    也尝试实现尺寸改变事件

    Window.Current.SizeChanged += OnWindowSizeChanged;
    

    并在那里应用相同的内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多