c# - XAML UWP 浮出控件定位

标签 c# xaml uwp windows-10-universal uwp-xaml

我正在 UWP 应用程序中实现 Flyout,如下图所示。我希望 Flyout 中的 AutoSuggestBox 出现在(并填充)PageHeader 中,但它出现在它的下方。 Screenshot

这是我的 XAML:

<Button x:Name="searchButton" Margin="0" Padding="0" BorderThickness="0" RelativePanel.AlignBottomWith="pageHeader">
        <Button.Content>
            <FontIcon Height="48" Width="48" Glyph="&#xE094;"/>
        </Button.Content>
        <Button.Flyout>
            <Flyout>
                <Flyout.FlyoutPresenterStyle>
                    <Style TargetType="FlyoutPresenter">
                        <Setter Property="Padding" Value="0"/>
                        <Setter Property="BorderThickness" Value="0"/>
                        <Setter Property="HorizontalAlignment" Value="Right"/>
                        <Setter Property="Height" Value="40"/>
                        <Setter Property="VerticalAlignment" Value="Top"/>
                    </Style>
                </Flyout.FlyoutPresenterStyle>
                <StackPanel Margin="0" VerticalAlignment="Top">
                    <AutoSuggestBox x:Name="innerSearchBox" PlaceholderText="Search" VerticalAlignment="Top"/>
                </StackPanel>
            </Flyout>
        </Button.Flyout>
    </Button>

如何让 AutoSugesstBox 出现并填充 PageHeader?

最佳答案

将布局设置为弹出按钮的左侧。

<Flyout Placement="Left">

如果要使AutoSuggestBox覆盖应用程序的整个宽度,请将AutoSuggestBox的宽度设置为ApplicationView宽度。

你可以这样做

public MainPage()
{
    this.InitializeComponent();
    ApplicationView.GetForCurrentView().VisibleBoundsChanged += MainPage_VisibleBoundsChanged;
    var bound = ApplicationView.GetForCurrentView().VisibleBounds;
    innerSearchBox.Width = (int)bound.Width - 48;        //48 is the size of the button
}

private void MainPage_VisibleBoundsChanged(ApplicationView sender, object args)
{
    var bound = ApplicationView.GetForCurrentView().VisibleBounds;
    innerSearchBox.Width = (int)bound.Width - 48;
}

关于c# - XAML UWP 浮出控件定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42820443/

相关文章:

c# - IPagedList.MVC,设置总大小?

c# - 暂停方法设置 # of milliseconds

c# - 带有 LineUp/LineDown 重复按钮的自定义 WPF DataGrid 滚动条

c# - 如何更改 UWP 的复选框背景?

c# - 如何在 Windows 10 IoT Core for Raspberry PI 3 中从 ASP.NET Core 2.1 调用 UWP 函数

c# - 当应用程序失去焦点时,允许不关闭丙烯酸吗?

c# - 使用 IIS .Net ASP.Net 中的 AWS S3 API 时,对象引用未设置为对象的实例

c# - 从注册表中读取值

.net - 我可以使用 WPF 窗口中的 XamlReader.Load 或 InitializeFromXaml 来进行窗口定义吗?

c# - 为什么我需要 'dummy' 行代码才能加载PresentationFramework?