【问题标题】:Content Dialog not showing up WINUI3内容对话框未显示 WINUI3
【发布时间】:2021-09-05 00:50:33
【问题描述】:

我正在尝试在我的应用中显示一个用于编辑品牌的弹出窗口,但它没有显示出来。

我调用对话框的函数:

private async Task EditBrandAsync(Brand brand)
{
    var dialog = new ContentDialogs.EditBrandDialog(brand);
    await dialog.ShowAsync();
}

ContentDialog XAML:

<ContentDialog
    x:Class="xizSoft.ContentDialogs.EditBrandDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:xizSoft.ContentDialogs"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <StackPanel>
        <TextBlock Text="Marca" Style="{StaticResource SubheaderTextBlockStyle}"/>

        <TextBox Header="Nome" Text="{Binding Name}"/>
        <TextBox Header="Logotipo" Text="{Binding LogoFileName}"/>

        <StackPanel>
            <Image Source="{Binding LogoFileName}"/>
        </StackPanel>
    </StackPanel>
</ContentDialog>

代码隐藏:

namespace xizSoft.ContentDialogs
{
  public sealed partial class EditBrandDialog : ContentDialog
    {
        public Brand _brand {get; set;}

        public EditBrandDialog(Brand brand)
        { 
            this.InitializeComponent();
            this.DataContext = _brand = brand;
        }
    }
}

我已经尝试过调试并且内容对话框正在被调用,所以我不知道为什么它没有出现。

【问题讨论】:

    标签: c# xaml uwp winui winui-3


    【解决方案1】:

    确保SubheaderTextBlockStyle 资源在范围内,并且您设置了ContentDialogXamlRoot 属性:

    private async Task EditBrandAsync(Brand brand)
    {
        var dialog = new ContentDialogs.EditBrandDialog(brand);
        dialog.XamlRoot = this.Content.XamlRoot;
        await dialog.ShowAsync();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 2013-06-28
      • 2016-05-30
      • 2017-02-05
      • 2017-07-03
      相关资源
      最近更新 更多