回答編集履歴

2

見直しキャンペーン中

2023/08/15 09:45

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,11 +1,12 @@
1
1
  `MenuItem.ToolTip`プロパティは`object`のため、`ToolTip`クラスを入れた場合はキャストがいります。
2
2
  [FrameworkElement.ToolTip プロパティ (System.Windows) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.frameworkelement.tooltip?view=net-6.0)
3
3
 
4
- shindan[j].Dataがなんだかわかりませんが、今`Anisakiasis`と出てるんだったら、
4
+ `shindan[j].Data`がなんだかわかりませんが、今`Anisakiasis`と出てるんだったら、↓でいいはずです。
5
5
  ```cs
6
6
  textEditor2.Text += ((ToolTip)item.ToolTip).Content.ToString();
7
7
  ```
8
+
8
- でいいはずです。
9
+ ---
9
10
 
10
11
  ```xml
11
12
  <Window

1

見直しキャンペーン中

2023/07/29 13:38

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,215 +1,108 @@
1
1
  `MenuItem.ToolTip`プロパティは`object`のため、`ToolTip`クラスを入れた場合はキャストがいります。
2
-
3
2
  [FrameworkElement.ToolTip プロパティ (System.Windows) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.frameworkelement.tooltip?view=net-6.0)
4
3
 
4
+ shindan[j].Dataがなんだかわかりませんが、今`Anisakiasis`と出てるんだったら、
5
+ ```cs
6
+ textEditor2.Text += ((ToolTip)item.ToolTip).Content.ToString();
7
+ ```
8
+ でいいはずです。
5
9
 
10
+ ```xml
11
+ <Window
12
+ x:Class="Questions375250.MainWindow"
13
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
14
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
15
+ Width="800"
16
+ Height="450">
17
+ <Window.Resources>
18
+ <Style TargetType="ToolTip">
19
+ <Style.Resources>
20
+ <Style TargetType="ContentPresenter">
21
+ <Style.Resources>
22
+ <Style TargetType="TextBlock">
23
+ <Setter Property="TextWrapping" Value="Wrap" />
24
+ </Style>
25
+ </Style.Resources>
26
+ </Style>
27
+ </Style.Resources>
28
+ <Setter Property="MaxWidth" Value="600" />
29
+ <Setter Property="Background" Value="Bisque" />
30
+ </Style>
31
+ </Window.Resources>
6
32
 
7
- shindan[j].Dataがなんだかわかりませんが、今`Anisakiasis`と出てるんだったら、
33
+ <DockPanel>
8
-
9
- ```C#
10
-
11
- textEditor2.Text += ((ToolTip)item.ToolTip).Content.ToString();
34
+ <Menu x:Name="menu" DockPanel.Dock="Top">
12
-
35
+ <MenuItem
36
+ Click="FileMenuItem_Click"
37
+ Header="ファイル(_F)"
38
+ ToolTip="ファイル - つーるちっぷ" />
39
+ </Menu>
40
+ <TextBox x:Name="textBox" />
41
+ </DockPanel>
42
+ </Window>
13
43
  ```
14
44
 
15
- でいいはずです。
16
-
17
-
18
-
19
- ```xaml
20
-
21
- <Window
22
-
23
- x:Class="Questions375250.MainWindow"
24
-
25
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
26
-
27
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
28
-
29
- Width="800"
30
-
31
- Height="450">
32
-
33
- <Window.Resources>
34
-
35
- <Style TargetType="ToolTip">
36
-
37
- <Style.Resources>
38
-
39
- <Style TargetType="ContentPresenter">
40
-
41
- <Style.Resources>
42
-
43
- <Style TargetType="TextBlock">
44
-
45
- <Setter Property="TextWrapping" Value="Wrap" />
46
-
47
- </Style>
48
-
49
- </Style.Resources>
50
-
51
- </Style>
52
-
53
- </Style.Resources>
54
-
55
- <Setter Property="MaxWidth" Value="600" />
56
-
57
- <Setter Property="Background" Value="Bisque" />
58
-
59
- </Style>
60
-
61
- </Window.Resources>
62
-
63
-
64
-
65
- <DockPanel>
66
-
67
- <Menu x:Name="menu" DockPanel.Dock="Top">
68
-
69
- <MenuItem
70
-
71
- Click="FileMenuItem_Click"
72
-
73
- Header="ファイル(_F)"
74
-
75
- ToolTip="ファイル - つーるちっぷ" />
76
-
77
- </Menu>
78
-
79
- <TextBox x:Name="textBox" />
80
-
81
- </DockPanel>
82
-
83
- </Window>
84
-
85
- ```
86
-
87
-
88
-
89
- ```C#
45
+ ```cs
90
-
91
46
  using System.Windows;
92
-
93
47
  using System.Windows.Controls;
94
-
95
48
  using System.Windows.Media;
96
49
 
97
-
98
-
99
50
  namespace Questions375250
100
-
101
51
  {
102
-
103
52
  public partial class MainWindow : Window
104
-
105
53
  {
106
-
107
54
  public MainWindow()
108
-
109
55
  {
110
-
111
56
  InitializeComponent();
112
57
 
113
-
114
-
115
58
  var editMenuItem = new MenuItem
116
-
117
59
  {
118
-
119
60
  Background = Brushes.Beige,
120
-
121
61
  Header = "編集(_E)",
122
-
123
62
  ToolTip = new ToolTip { Content = "編集 - つーるちっぷ", },
124
-
125
63
  };
126
-
127
64
  editMenuItem.Click += EditMenuItem_Click;
128
-
129
65
  menu.Items.Add(editMenuItem);
130
66
 
131
-
132
-
133
67
  var viewMenuItem = new MenuItem
134
-
135
68
  {
136
-
137
69
  Background = Brushes.Beige,
138
-
139
70
  Header = "表示(_V)",
140
-
141
71
  ToolTip = new ToolTip { Content = "表示 - つーるちっぷ", },
142
-
143
72
  };
144
-
145
73
  viewMenuItem.Click += ViewMenuItem_Click;
146
-
147
74
  menu.Items.Add(viewMenuItem);
148
-
149
75
  }
150
76
 
151
-
152
-
153
77
  private void FileMenuItem_Click(object sender, RoutedEventArgs e)
154
-
155
78
  {
156
-
157
79
  var item = (MenuItem)sender;
158
80
 
159
-
160
-
161
81
  // ファイルMenuItemはToolTipプロパティに直接文字列だから、item.ToolTipは文字列
162
-
163
82
  textBox.Text += item.ToolTip.ToString(); // ファイル - つーるちっぷ
164
-
165
83
  textBox.Text += "\n";
166
-
167
84
  }
168
85
 
169
-
170
-
171
86
  private void EditMenuItem_Click(object sender, RoutedEventArgs e)
172
-
173
87
  {
174
-
175
88
  var item = (MenuItem)sender;
176
89
 
177
-
178
-
179
90
  // 編集MenuItemはToolTipプロパティにToolTipクラスが入っているから、item.ToolTipはToolTipクラス
180
-
181
91
  // ToStringすると型名が出る
182
-
183
92
  textBox.Text += item.ToolTip.ToString(); // System.Windows.Controls.ToolTip: 編集 - つーるちっぷ
184
-
185
93
  textBox.Text += "\n";
186
-
187
94
  }
188
95
 
189
-
190
-
191
96
  private void ViewMenuItem_Click(object sender, RoutedEventArgs e)
192
-
193
97
  {
194
-
195
98
  var item = (MenuItem)sender;
196
99
 
197
-
198
-
199
100
  // 表示MenuItemはToolTipプロパティにToolTipクラスが入っているから、item.ToolTipはToolTipクラス
200
-
201
101
  // キャストしてContentで取り出せる
202
-
203
102
  textBox.Text += ((ToolTip)item.ToolTip).Content.ToString(); // 表示 - つーるちっぷ
204
-
205
103
  textBox.Text += "\n";
206
-
207
104
  }
208
-
209
105
  }
210
-
211
106
  }
212
-
213
107
  ```
214
-
215
108
  ![アプリ画像](e77966a257fb6f06fce36de9d819b45d.png)