HeartFireY 2022-01-07 23:40 采纳率: 100%
浏览 235
已结题

WINUI3对话框报错System.ArgumentException:“Value does not fall within the expected range.”

问题遇到的现象和发生背景

img

img

如上图所示的代码中,一运行点按钮后就会报错:System.ArgumentException:“Value does not fall within the expected range.”

img

问题相关代码,请勿粘贴截图
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace ACSMaid
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

        private void myButton_Click(object sender, RoutedEventArgs e)
        {
            myButton.Content = "Clicked";
            //ClientModel clientModel = new ClientModel();
            //clientModel.StarUp();
            DisplayNoWifiDialog();
        }

        private async void DisplayNoWifiDialog()
        {
            ContentDialog noWifiDialog = new ContentDialog
            {
                Title = "No wifi connection",
                Content = "Check your connection and try again.",
                CloseButtonText = "Ok"
            };

            ContentDialogResult result = await noWifiDialog.ShowAsync();
        }
    }
}
  • 写回答

2条回答 默认 最新

  • SEREINMONO 2022-04-15 22:06
    关注

    请加入“contentDialog.XamlRoot = this.Content.XamlRoot”

    
     
    var contentDialog = new ContentDialog()
    {
        Content = new Content("This is a transparent ContentDialog."),
        PrimaryButtonText = "确定",
    };
    contentDialog.XamlRoot = this.Content.XamlRoot;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月11日
  • 已采纳回答 9月3日
  • 修改了问题 1月7日
  • 创建了问题 1月7日

悬赏问题

  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能