小编Dav*_*ões的帖子

System.ArgumentException:“值不在预期范围内。” 在内容对话框上

我正在尝试在我的 UWP (WinUI3) 应用程序中创建一个登录系统,当我尝试启动登录内容对话框时,它崩溃并抛出此错误:

System.ArgumentException:“值不在预期范围内。”

await messageDialog.ShowAsync();

app.xaml.cs 上的代码:

protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{

    m_window = new MainWindow();
    m_window.Activate();

    Login();

}

protected async void Login()
{
    var messageDialog = new ContentDialogs.LoginDialog();
    await messageDialog.ShowAsync();

    if (App.Aplicacao.Utilizador == null)
    {
        m_window.Close();
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

内容对话框 XAML:

<ContentDialog
    x:Class="xizSoft.ContentDialogs.LoginDialog"
    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 SystemControlAcrylicWindowBrush}">

    <Grid>
    </Grid>
</ContentDialog>
Run Code Online (Sandbox Code Playgroud)

隐藏代码:

public LoginDialog()
{
    this.InitializeComponent();
}
Run Code Online (Sandbox Code Playgroud)

c# uwp winui winui-3

6
推荐指数
1
解决办法
6200
查看次数

WINUI3 内容对话框不显示

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

我调用对话框的函数:

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

内容对话框 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>
Run Code Online (Sandbox Code Playgroud)

隐藏代码:

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

        public EditBrandDialog(Brand brand)
        { 
            this.InitializeComponent();
            this.DataContext = _brand = brand;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试进行调试并且正在调用内容对话框,所以我不知道为什么它没有显示。

c# xaml uwp winui winui-3

6
推荐指数
1
解决办法
3685
查看次数

标签 统计

c# ×2

uwp ×2

winui ×2

winui-3 ×2

xaml ×1