回答編集履歴

1

見直しキャンペーン中

2023/07/29 04:40

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,317 +1,159 @@
1
1
  > 動画プレイヤーを学習の一環として作ってみようと考えていますが、On/Offできる操作パネルのレイアウト方法で困っています。
2
2
 
3
-
4
-
5
3
  私も過去に何度か挑戦しているんですが、なかなか「これが決定版!」というのはできてないんですよねぇ(WinUI 3で`MediaPlayerElement`が使えるようになるんだったら、用済みになりそうというのもあります^^;
6
-
7
4
  [メディア プレーヤー - Windows apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/apps/design/controls/media-playback)
8
-
9
-
10
-
11
5
 
12
6
 
13
7
  Baseさんのイメージとはちょっと違うのかな?という気もしますが、
14
8
 
15
-
16
-
17
9
  > もし他のアイディアもあれば、記載いただけたら嬉しいです。
18
10
 
19
-
20
-
21
11
  ということなので「しばらくマウス操作がなければ消える」というのはどうでしょう?
22
-
23
12
  割と今風?ですし、何もしなくていいので(ユーザー目線で)楽な感じはします。
24
13
 
25
-
26
-
27
14
  3秒間ウィンドウ内でマウスが動かなかった場合、下方向にスーッとスライドアウトします。
28
-
29
15
  マウスが動くとシュッとスライドインします(秒数やイージング具合はお好みで)
30
-
31
-
32
16
 
33
17
  こだわりポイントはシークバーをわざと見切れるようにして、隠れた状態でも再生位置がわかるようになっているところですw
34
18
 
35
-
36
-
37
19
  実際のプロジェクトではカスタムコントロールですが、最低限に簡略化するとこんな感じです。
38
20
 
39
-
40
-
41
- ```xaml
21
+ ```xml
42
-
43
22
  <Window
44
-
45
23
  x:Class="Questions358311.MainWindow"
46
-
47
24
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
48
-
49
25
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
50
-
51
26
  Width="800"
52
-
53
27
  Height="450">
54
-
55
28
  <Grid
56
-
57
29
  x:Name="grid"
58
-
59
30
  Background="Transparent"
60
-
61
31
  ClipToBounds="True">
62
-
63
32
  <Grid.Resources>
64
-
65
33
  <Style TargetType="{x:Type Button}">
66
-
67
34
  <Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
68
-
69
35
  <Setter Property="Width" Value="40" />
70
-
71
36
  <Setter Property="Height" Value="40" />
72
-
73
37
  </Style>
74
-
75
38
  </Grid.Resources>
76
39
 
77
-
78
-
79
40
  <!--<MediaElement />-->
80
-
81
41
  <!-- MediaElementのかわりにとりあえずImage -->
82
-
83
42
  <Image Source="https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg" />
84
43
 
85
-
86
-
87
44
  <StackPanel x:Name="lowerArea" VerticalAlignment="Bottom">
88
-
89
45
  <StackPanel.Background>
90
-
91
46
  <LinearGradientBrush MappingMode="RelativeToBoundingBox" StartPoint="0.5,0" EndPoint="0.5,1">
92
-
93
47
  <GradientStop Offset="1" Color="#CC000000" />
94
-
95
48
  <GradientStop Color="#00000000" />
96
-
97
49
  </LinearGradientBrush>
98
-
99
50
  </StackPanel.Background>
100
-
101
51
  <ProgressBar
102
-
103
52
  Height="30"
104
-
105
53
  Background="#00E6E6E6"
106
-
107
54
  Foreground="#340034B2"
108
-
109
55
  Value="50" />
110
-
111
56
  <Grid>
112
-
113
57
  <Grid.ColumnDefinitions>
114
-
115
58
  <ColumnDefinition />
116
-
117
59
  <ColumnDefinition Width="Auto" />
118
-
119
60
  <ColumnDefinition />
120
-
121
61
  </Grid.ColumnDefinitions>
122
-
123
62
  <StackPanel Orientation="Horizontal">
124
-
125
63
  <Button Command="MediaCommands.MuteVolume" Content="&#xE767;" />
126
-
127
64
  <Slider
128
-
129
65
  Width="125"
130
-
131
66
  VerticalAlignment="Center"
132
-
133
67
  IsMoveToPointEnabled="True" />
134
-
135
68
  </StackPanel>
136
-
137
69
  <StackPanel
138
-
139
70
  Grid.Column="1"
140
-
141
71
  Margin="10"
142
-
143
72
  HorizontalAlignment="Center"
144
-
145
73
  Orientation="Horizontal">
146
-
147
74
  <Button Command="MediaCommands.PreviousTrack" Content="&#xE892;" />
148
-
149
75
  <Button Command="MediaCommands.Play" Content="&#xE768;" />
150
-
151
76
  <Button Command="MediaCommands.Pause" Content="&#xE769;" />
152
-
153
77
  <Button Command="MediaCommands.NextTrack" Content="&#xE893;" />
154
-
155
78
  </StackPanel>
156
-
157
79
  </Grid>
158
-
159
80
  </StackPanel>
160
-
161
81
  <VisualStateManager.VisualStateGroups>
162
-
163
82
  <VisualStateGroup x:Name="ControllerStates">
164
-
165
83
  <VisualState x:Name="ControllerHide">
166
-
167
84
  <Storyboard>
168
-
169
85
  <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
170
-
171
86
  <EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,0,0,-85">
172
-
173
87
  <EasingThicknessKeyFrame.EasingFunction>
174
-
175
88
  <ExponentialEase EasingMode="EaseIn" />
176
-
177
89
  </EasingThicknessKeyFrame.EasingFunction>
178
-
179
90
  </EasingThicknessKeyFrame>
180
-
181
91
  </ThicknessAnimationUsingKeyFrames>
182
-
183
92
  </Storyboard>
184
-
185
93
  </VisualState>
186
-
187
94
  <VisualState x:Name="ControllerShow">
188
-
189
95
  <Storyboard>
190
-
191
96
  <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
192
-
193
97
  <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0,0,0,0">
194
-
195
98
  <EasingThicknessKeyFrame.EasingFunction>
196
-
197
99
  <CubicEase EasingMode="EaseIn" />
198
-
199
100
  </EasingThicknessKeyFrame.EasingFunction>
200
-
201
101
  </EasingThicknessKeyFrame>
202
-
203
102
  </ThicknessAnimationUsingKeyFrames>
204
-
205
103
  </Storyboard>
206
-
207
104
  </VisualState>
208
-
209
105
  </VisualStateGroup>
210
-
211
106
  </VisualStateManager.VisualStateGroups>
212
-
213
107
  </Grid>
214
-
215
108
  </Window>
216
-
217
109
  ```
218
110
 
219
-
220
-
221
- ```C#
111
+ ```cs
222
-
223
112
  using System;
224
-
225
113
  using System.Windows;
226
-
227
114
  using System.Windows.Input;
228
-
229
115
  using System.Windows.Threading;
230
116
 
231
-
232
-
233
117
  namespace Questions358311
234
-
235
118
  {
236
-
237
119
  public partial class MainWindow : Window
238
-
239
120
  {
240
-
241
121
  private readonly DispatcherTimer hideTimer;
242
-
243
122
  private bool isHide;
244
123
 
245
-
246
-
247
124
  public MainWindow()
248
-
249
125
  {
250
-
251
126
  InitializeComponent();
252
127
 
253
-
254
-
255
128
  hideTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3), };
256
-
257
129
  hideTimer.Tick += (s, e) =>
258
-
259
130
  {
260
-
261
131
  hideTimer.Stop();
262
-
263
132
  isHide = true;
264
-
265
133
  UpdateStates(true);
266
-
267
134
  };
268
-
269
135
  }
270
136
 
271
-
272
-
273
137
  private void UpdateStates(bool useTransitions)
274
-
275
138
  {
276
-
277
139
  if (isHide) VisualStateManager.GoToElementState(grid, "ControllerHide", useTransitions);
278
-
279
140
  else VisualStateManager.GoToElementState(grid, "ControllerShow", useTransitions);
280
-
281
141
  }
282
142
 
283
-
284
-
285
143
  protected override void OnMouseMove(MouseEventArgs e)
286
-
287
144
  {
288
-
289
145
  base.OnMouseMove(e);
290
146
 
291
-
292
-
293
147
  isHide = false;
294
-
295
148
  UpdateStates(true);
296
149
 
297
-
298
-
299
150
  hideTimer.Start();
300
-
301
151
  }
302
-
303
152
  }
304
-
305
153
  }
306
-
307
154
  ```
308
-
309
155
  ![アプリ画像 - コントローラ表示](7b94b3adde3b7e8e10a71a383978bd54.png)
310
-
311
156
  ![アプリ画像 - コントローラ非表示](33104cc2a55552e0ac86a53f4ef637c6.png)
312
157
 
313
-
314
-
315
158
  本来はボタン等にスタイルを当てていますが、無駄に長くなるので省略。
316
-
317
159
  コントローラ上にマウスを置きっぱにするとちょっとピクピクします(ちゃんとやろうとするとかなり面倒なので^^;