gpt4 book ai didi

c# - 如何在 Windows 8.1 中使用 SettingsFlyout 的完整高度和宽度

转载 作者:太空宇宙 更新时间:2023-11-03 19:07:22 24 4
gpt4 key购买 nike

我有一个带有设置弹出窗口的 Windows 8.1 应用程序,当您单击设置 super 按钮栏中的自定义设置时,它会打开。

但是,我在设置弹出窗口中的内容没有使用设置弹出窗口的完整高度/宽度,而是在所有角上都有统一的边距。下图显示相同。

enter image description here

为了更好地理解,我使用了黑色和红色背景。黑色背景用于 SettingsFlyout,红色背景用于 Flyout 内的 StackPanel。我已将 StackPanel 的高度和宽度设置为弹出窗口的实际高度和实际宽度这是 XAML

<SettingsFlyout
x:Name="AccountsSettingsFlyoutElement"
x:Class="Something.AccountsSettingsFlyout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="Black"
mc:Ignorable="d"
IconSource="Assets/SmallLogo.png"
Title="Accounts"
d:DesignWidth="346">

<!-- This StackPanel acts as a root panel for vertical layout of the content sections -->
<StackPanel Background="Red"
Width="{Binding ElementName=AccountsSettingsFlyoutElement, Path=ActualWidth}"
Height="{Binding ElementName=AccountsSettingsFlyoutElement, Path=ActualHeight}">
<StackPanel Style="{StaticResource SettingsFlyoutSectionStyle}">
<TextBlock Text="Accounts"
x:Uid="AccountsSettings_Title"
VerticalAlignment="Bottom"
Style="{StaticResource SettingTitleStyle}" />

</StackPanel>
</StackPanel>

如您所见,红色并未覆盖整个黑色区域。我想创建一个这样的 UI。

enter image description here

现在,如果您注意到上图的底部。添加帐户按钮覆盖了弹出窗口的整个宽度。

如何实现与此类似的 UI?

最佳答案

ActualHeight 不是依赖属性,因此绑定(bind)可能无法正常工作。 “绑定(bind)”高度的方法是使用像这样的 SizeChanged 事件处理程序。

    private void ScrollViewer_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
YourGrid.Width = e.NewSize.Width;
YourGrid.Height = e.NewSize.Height;
}

SettingsFlyout 样式具有内置的填充。要使用内容的总面积,请将 padding 属性设置为 0。

<SettingsFlyout x:Class="ApplicationSettings.SettingsFlyout1"
Padding="0" ...

最后,要设置正确的大小,请使用内容展示器的大小。

<ScrollViewer x:Name="ScrollViewer"
AutomationProperties.AccessibilityView="Raw"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
Grid.Row="1"
SizeChanged="ScrollViewer_OnSizeChanged"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">
<ContentPresenter x:Name="ContentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{Binding TemplateSettings.ContentTransitions, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</ScrollViewer>

Full-size settings flyout

关于c# - 如何在 Windows 8.1 中使用 SettingsFlyout 的完整高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25065126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com