xaml - 将 ContentDialog 设置为在 UWP 页面底部显示

标签 xaml dialog uwp windows-phone

我在 RelativeLayout 中有几个 ContentDialogs 并希望它们出现或垂直对齐到“底部”。但似乎无论我尝试什么,对话框总是出现在屏幕顶部。 这是他们现在的样子

enter image description here

有什么想法吗? 这是一个 xaml 代码片段:

    <RelativePanel Height="{Binding ActualHeight, ElementName=Page}" >
                <ContentDialog x:Name="EntrepriseDialog"
                        VerticalAlignment="Bottom"
                               Title="Vælg entreprise"
                           PrimaryButtonText=""
                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}" Grid.ColumnSpan="2" Margin="30,194,-71,-194">
                    <ListView Name="ListEntreprises" VerticalAlignment="Bottom" SelectionChanged="ListEntreprises_SelectionChanged">
                        <ListView.ItemContainerStyle>
                            <Style TargetType="ListViewItem">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                                <Setter Property="Margin" Value="0,0,0,1"></Setter>
                                <Setter Property="Background" Value="Transparent"></Setter>
                                <Setter Property="Padding" Value="5"></Setter>
                            </Style>
                        </ListView.ItemContainerStyle>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <StackPanel>
                                        <TextBlock>
                            <Run FontSize="15" Text="{Binding Name}"/>
                                        </TextBlock>
                                        <TextBlock Visibility="Collapsed">
                                    <Run Text="{Binding Id}"/>
                                        </TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </ContentDialog>
                <ContentDialog x:Name="SaveChooseDialog"
                        VerticalAlignment="Bottom"
                        Title=""
                           PrimaryButtonText=""

                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}" Grid.ColumnSpan="2" Margin="30,148,-71,-148">
                    <ListBox Name="ListBoxSaveMode"  SelectionChanged="ListBoxSaveMode_SelectionChanged">
                        <ListBoxItem>
                            <TextBlock Name="TxtLocally" Text="Gem lokalt"/>
                        </ListBoxItem>
                        <ListBoxItem>
                            <TextBlock Name="TxtServer" Text="Gem på server"/>
                        </ListBoxItem>
                        <ListBoxItem>
                            <TextBlock Name="TxtCancel" Text="Annullér"/>
                        </ListBoxItem>
                    </ListBox>
                </ContentDialog>
                <ContentDialog x:Name="AddPictureDialog"
                        VerticalAlignment="Bottom"
                        Title=""
                           PrimaryButtonText=""

                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}" Grid.ColumnSpan="2" Margin="30,142,-71,-142">
                    <ListBox Name="ListBoxAddPicture"  SelectionChanged="ListBoxAddPicture_SelectionChanged">
                        <ListBoxItem>
                            <TextBlock Name="TxtFromCamera" Text="Tag et nyt"/>
                        </ListBoxItem>
                        <ListBoxItem>
                            <TextBlock Name="TxtFromStorage" Text="Vælg fra kamerarulle"/>
                        </ListBoxItem>
                    </ListBox>
                </ContentDialog>
            </RelativePanel>

编辑:整个页面的 XAML

<Page
Name="Page"
x:Class="...Pages.Documentation.DocumentationCreatePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:...Pages.Documentation"
xmlns:userControl="using:...Pages.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="#8FBC3E">
<Grid>
    <Grid.Background>
        <ImageBrush Stretch="UniformToFill" ImageSource="/Assets/Images/mainBg.png" />
    </Grid.Background>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <StackPanel>
        <Grid Height="40" Background="#8FBC3E" >
            <StackPanel Orientation="Horizontal">
                <Button Name="BtnBack" Click="BtnBack_Click" Margin="20 0 20 0" >
                    <Button.Template>
                        <ControlTemplate>
                            <TextBlock  FontSize="20" Foreground="White" FontFamily="Segoe MDL2 Assets" Text="&#xE0A6;"></TextBlock>
                        </ControlTemplate>
                    </Button.Template>
                </Button>
                <TextBlock Name="TxtTitle" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="18"/>
            </StackPanel>
        </Grid>
        <userControl:SyncDataControl></userControl:SyncDataControl>
    </StackPanel>
    <Grid Grid.Row="1" Name="StackPanel">
        <ProgressRing Name="SaveProgressRing" IsActive="False" Foreground="#8FBC3E" Width="40" Height="40" Margin="152,239,87,321"  />
        <StackPanel Grid.ColumnSpan="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <ListView Name="ListViewDocumentationItems" ScrollViewer.VerticalScrollMode="Disabled" SelectionChanged="ListViewDocumentationItems_SelectionChanged">
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="Height" Value="80"></Setter>
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
                        <Setter Property="Margin" Value="0,0,0,1"></Setter>
                        <Setter Property="Background" Value="White"></Setter>
                    </Style>
                </ListView.ItemContainerStyle>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid VerticalAlignment="Center">
                            <StackPanel Padding="0 0 10 0" Orientation="Horizontal" >
                                <Image Source="{Binding ImageSource}" VerticalAlignment="Center" Height="40" Margin="5 0 5 0"></Image>
                                <TextBlock Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Center">
                                    <Run FontWeight="Bold" FontSize="20" Text="{Binding Name}"/>
                                </TextBlock>
                            </StackPanel>
                            <Grid HorizontalAlignment="Right">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Foreground="Black" VerticalAlignment="Center" Padding="0 0 20 0">
                                    <Run FontSize="15" Text="{Binding Count}"/>
                                    </TextBlock>
                                    <Image Width="15" Height="15" VerticalAlignment="Center" Source="/Assets/Images/rightarrow.png" />
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <TextBlock Name="TxtDocDesc" TextWrapping="Wrap" Foreground="Gray" Height="53" />
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <StackPanel Name="PicturePanel" Orientation="Horizontal" Margin="15 0 15 0" />
            </ScrollViewer>
        </StackPanel>
        <Button Name="BtnSave" Grid.Row="2" VerticalAlignment="Bottom" FontSize="25" Click="BtnSave_Click" Background="#8FBC3E" Foreground="White" Height="60" Content="Gem" HorizontalAlignment="Stretch" Margin="5 5 5 5"/>
        <RelativePanel VerticalAlignment="Stretch"  >
            <ContentDialog x:Name="EntrepriseDialog" VerticalContentAlignment="Bottom"
                        RelativePanel.AlignBottomWithPanel="True"
                               Title="Vælg entreprise"
                           PrimaryButtonText=""
                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}" >
                <ListView Name="ListEntreprises" VerticalAlignment="Bottom" SelectionChanged="ListEntreprises_SelectionChanged">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                            <Setter Property="Margin" Value="0,0,0,1"></Setter>
                            <Setter Property="Background" Value="Transparent"></Setter>
                            <Setter Property="Padding" Value="5"></Setter>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel>
                                    <TextBlock>
                            <Run FontSize="15" Text="{Binding Name}"/>
                                    </TextBlock>
                                    <TextBlock Visibility="Collapsed">
                                    <Run Text="{Binding Id}"/>
                                    </TextBlock>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </ContentDialog>
            <ContentDialog x:Name="SaveChooseDialog"
                        RelativePanel.AlignBottomWithPanel="True"
                        Title=""
                           PrimaryButtonText=""
                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}">
                <ListBox Name="ListBoxSaveMode"  SelectionChanged="ListBoxSaveMode_SelectionChanged">
                    <ListBoxItem>
                        <TextBlock Name="TxtLocally" Text="Gem lokalt"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Name="TxtServer" Text="Gem på server"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Name="TxtCancel" Text="Annullér"/>
                    </ListBoxItem>
                </ListBox>
            </ContentDialog>
            <ContentDialog x:Name="AddPictureDialog"
                        Title=""
                        PrimaryButtonText=""
                        IsPrimaryButtonEnabled="{Binding IsChecked, ElementName=checkBoxAgree, Mode=OneWay}"
                        MaxWidth="{Binding ActualWidth, ElementName=pageRoot}" >
                <ListBox Name="ListBoxAddPicture" SelectionChanged="ListBoxAddPicture_SelectionChanged">
                    <ListBoxItem>
                        <TextBlock Name="TxtFromCamera" Text="Tag et nyt"/>
                    </ListBoxItem>
                    <ListBoxItem>
                        <TextBlock Name="TxtFromStorage" Text="Vælg fra kamerarulle"/>
                    </ListBoxItem>
                </ListBox>
            </ContentDialog>
            <ContentDialog x:Name="DialogDownloadProgress" 
                   VerticalAlignment="Stretch"
                   Title=""
                   MaxWidth="{Binding ActualWidth, ElementName=pageRoot}">
                <StackPanel Padding="0,50">
                    <TextBlock Name="ProgressTitle" Text="Test test" HorizontalAlignment="Center" Padding="0 0 0 20"/>
                    <ProgressBar x:Name="ProgressBarDownload" HorizontalAlignment="Stretch" IsEnabled="True"></ProgressBar>
                </StackPanel>
            </ContentDialog>
        </RelativePanel>
    </Grid>
</Grid>

最佳答案

ContentDialog 实例的定位似乎不在开发者手中,至少在没有自定义版本的情况下是这样。 Afaik 操作系统将为您决定将对话框放置在何处。

更多信息请看这里:

http://www.reflectionit.nl/blog/2015/windows-10-xaml-tips-messagedialog-and-contentdialog

因此,如果对话框的定位很重要,那么您可能必须创建一个自定义控件。

关于xaml - 将 ContentDialog 设置为在 UWP 页面底部显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732210/

相关文章:

c# - 如何设置窗口的调整大小限制?

java - 当我尝试显示 DatePickerDialog 时出现 BadTokenException

c# - 使用 x :Bind with MvvmCross

windows - Windows 上的应用程序容器是什么?

c# - 找不到名称/键 X 的资源

xaml - 将 StringFormat 与单个绑定(bind)一起使用的正确语法是什么?

wpf - 自定义控件不继承父级的样式

xaml - 使用RelativePanel 与面板中心右对齐

c++ - 如何检查其他程序是否以全屏模式运行,例如。媒体播放器

c++ - 如何根据父对话框中设置的变量在子 MFC 对话框中显示值?