回答編集履歴

2

SubWindow Close 考慮漏れ

2023/06/14 14:52

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -85,16 +85,14 @@
85
85
  x:Class="Qt6uox4f1iujybm.SubWindow"
86
86
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
87
87
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
88
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
89
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
90
88
  Title="SubWindow"
91
89
  Width="800"
92
90
  Height="450"
93
91
  AllowDrop="True"
92
+ Closing="Window_Closing"
94
93
  DragOver="File_DragOver"
95
94
  Drop="File_Drop"
96
- Visibility="{Binding IsSubWindowShown, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter}}"
95
+ Visibility="{Binding IsSubWindowShown, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter}}">
97
- mc:Ignorable="d">
98
96
  <DockPanel>
99
97
  <StatusBar DockPanel.Dock="Bottom">
100
98
  <StatusBarItem>
@@ -133,7 +131,7 @@
133
131
 
134
132
  <GridSplitter Grid.Column="1" HorizontalAlignment="Stretch" />
135
133
 
136
- <ListView Grid.Column="2" d:ItemsSource="{d:SampleData}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Items}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
134
+ <ListView Grid.Column="2" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Items}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
137
135
  <ListView.ItemsPanel>
138
136
  <ItemsPanelTemplate>
139
137
  <WrapPanel />
@@ -154,6 +152,7 @@
154
152
  ```
155
153
  ```cs
156
154
  using System;
155
+ using System.ComponentModel;
157
156
  using System.IO;
158
157
  using System.Linq;
159
158
  using System.Windows;
@@ -163,9 +162,9 @@
163
162
 
164
163
  public partial class SubWindow : Window
165
164
  {
166
- private static string[] SupportedFormats = { ".jpg", ".jpeg", ".bmp", ".png" };
165
+ private static readonly string[] SupportedFormats = { ".jpg", ".jpeg", ".bmp", ".png" };
167
-
166
+
168
- private ViewModel viewModel;
167
+ private readonly ViewModel viewModel;
169
168
 
170
169
  public SubWindow(ViewModel viewModel)
171
170
  {
@@ -200,6 +199,12 @@
200
199
 
201
200
  var ng = files.Where(x => !SupportedFormats.Contains(Path.GetExtension(x).ToLower()));
202
201
  if (ng.Any()) MessageBox.Show(this, $"{string.Join("\n", ng)}\nのファイルは読めませんでした");
202
+ }
203
+
204
+ private void Window_Closing(object sender, CancelEventArgs e)
205
+ {
206
+ e.Cancel = true;
207
+ Hide();
203
208
  }
204
209
  }
205
210
  ```

1

using並び替え

2023/06/14 11:37

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -206,14 +206,14 @@
206
206
 
207
207
  ViewModel&Model
208
208
  ```cs
209
+ using System;
209
210
  using System.Collections.Generic;
210
211
  using System.Collections.ObjectModel;
212
+ using System.Diagnostics;
211
213
  using System.IO;
214
+ using System.Linq;
212
215
  using System.Windows.Media.Imaging;
213
- using System;
214
216
  using CommunityToolkit.Mvvm.ComponentModel;
215
- using System.Linq;
216
- using System.Diagnostics;
217
217
  using CommunityToolkit.Mvvm.Input;
218
218
 
219
219
  namespace Qt6uox4f1iujybm;