回答編集履歴

2

リンク

2025/01/26 15:19

投稿

TN8001
TN8001

スコア9937

test CHANGED
@@ -1,6 +1,7 @@
1
1
  > エラーメッセージ
2
2
 
3
+ 書いてある通りその時点では、`Application.Current`が`null`です。
3
- 書いてある通りその時点では[Application.Current](https://learn.microsoft.com/ja-jp/dotnet/api/microsoft.maui.controls.application.current)が`null`です。
4
+ [Application.Current プロパティ (Microsoft.Maui.Controls) | Microsoft Learn](https://learn.microsoft.com/ja-jp/dotnet/api/microsoft.maui.controls.application.current)
4
5
 
5
6
  `Application.Current`が入った後ならどこでもいいんでしょうが、一番手軽なのは`MainPage`のコンストラクタあたりでしょうか?
6
7
 

1

Window

2025/01/26 15:16

投稿

TN8001
TN8001

スコア9937

test CHANGED
@@ -33,3 +33,57 @@
33
33
  > ```
34
34
 
35
35
  本当はページなのにウィンドウを名乗るのは、かなり気持ちが悪いです^^;
36
+
37
+
38
+ 「.NET MAUI Window (XAML)」に変更すれば、名前通りになりますね^^
39
+ ```xml:DebugWindow.xaml
40
+ <?xml version="1.0" encoding="utf-8" ?>
41
+ <Window
42
+ x:Class="Q6ezm2rj0la9dh8.DebugWindow"
43
+ xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
44
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
45
+ Title="DebugWindow">
46
+ <ContentPage>
47
+ <ScrollView>
48
+ <Label x:Name="Label_message" />
49
+ </ScrollView>
50
+ </ContentPage>
51
+ </Window>
52
+ ```
53
+ ```cs:DebugWindow.xaml.cs
54
+ namespace Q6ezm2rj0la9dh8;
55
+
56
+ public partial class DebugWindow : Window
57
+ {
58
+ public DebugWindow()
59
+ {
60
+ InitializeComponent();
61
+
62
+ var w = Application.Current!.Windows[0];
63
+ X = w.X + w.Width;
64
+ Y = w.Y;
65
+ Width = 300;
66
+ Height = 500;
67
+ }
68
+
69
+ public void AddMessage(string message)
70
+ {
71
+ Label_message.Text += message;
72
+ }
73
+ }
74
+ ```
75
+ ```cs:MainPage.xaml.cs
76
+ namespace Q6ezm2rj0la9dh8;
77
+
78
+ public partial class MainPage : ContentPage
79
+ {
80
+ public MainPage()
81
+ {
82
+ InitializeComponent();
83
+
84
+ var debugWindow = new DebugWindow();
85
+ CommonData.SetDebugWindowInfo(debugWindow);
86
+ Application.Current!.OpenWindow(debugWindow);
87
+ }
88
+ }
89
+ ```