回答編集履歴

1

見直しキャンペーン中

2023/07/29 04:40

投稿

TN8001
TN8001

スコア10106

answer CHANGED
@@ -1,159 +1,159 @@
1
- > 動画プレイヤーを学習の一環として作ってみようと考えていますが、On/Offできる操作パネルのレイアウト方法で困っています。
2
-
3
- 私も過去に何度か挑戦しているんですが、なかなか「これが決定版!」というのはできてないんですよねぇ(WinUI 3で`MediaPlayerElement`が使えるようになるんだったら、用済みになりそうというのもあります^^;
4
- [メディア プレーヤー - Windows apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/apps/design/controls/media-playback)
5
-
6
-
7
- Baseさんのイメージとはちょっと違うのかな?という気もしますが、
8
-
9
- > もし他のアイディアもあれば、記載いただけたら嬉しいです。
10
-
11
- ということなので「しばらくマウス操作がなければ消える」というのはどうでしょう?
12
- 割と今風?ですし、何もしなくていいので(ユーザー目線で)楽な感じはします。
13
-
14
- 3秒間ウィンドウ内でマウスが動かなかった場合、下方向にスーッとスライドアウトします。
15
- マウスが動くとシュッとスライドインします(秒数やイージング具合はお好みで)
16
-
17
- こだわりポイントはシークバーをわざと見切れるようにして、隠れた状態でも再生位置がわかるようになっているところですw
18
-
19
- 実際のプロジェクトではカスタムコントロールですが、最低限に簡略化するとこんな感じです。
20
-
21
- ```xaml
22
- <Window
23
- x:Class="Questions358311.MainWindow"
24
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
25
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
26
- Width="800"
27
- Height="450">
28
- <Grid
29
- x:Name="grid"
30
- Background="Transparent"
31
- ClipToBounds="True">
32
- <Grid.Resources>
33
- <Style TargetType="{x:Type Button}">
34
- <Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
35
- <Setter Property="Width" Value="40" />
36
- <Setter Property="Height" Value="40" />
37
- </Style>
38
- </Grid.Resources>
39
-
40
- <!--<MediaElement />-->
41
- <!-- MediaElementのかわりにとりあえずImage -->
42
- <Image Source="https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg" />
43
-
44
- <StackPanel x:Name="lowerArea" VerticalAlignment="Bottom">
45
- <StackPanel.Background>
46
- <LinearGradientBrush MappingMode="RelativeToBoundingBox" StartPoint="0.5,0" EndPoint="0.5,1">
47
- <GradientStop Offset="1" Color="#CC000000" />
48
- <GradientStop Color="#00000000" />
49
- </LinearGradientBrush>
50
- </StackPanel.Background>
51
- <ProgressBar
52
- Height="30"
53
- Background="#00E6E6E6"
54
- Foreground="#340034B2"
55
- Value="50" />
56
- <Grid>
57
- <Grid.ColumnDefinitions>
58
- <ColumnDefinition />
59
- <ColumnDefinition Width="Auto" />
60
- <ColumnDefinition />
61
- </Grid.ColumnDefinitions>
62
- <StackPanel Orientation="Horizontal">
63
- <Button Command="MediaCommands.MuteVolume" Content="&#xE767;" />
64
- <Slider
65
- Width="125"
66
- VerticalAlignment="Center"
67
- IsMoveToPointEnabled="True" />
68
- </StackPanel>
69
- <StackPanel
70
- Grid.Column="1"
71
- Margin="10"
72
- HorizontalAlignment="Center"
73
- Orientation="Horizontal">
74
- <Button Command="MediaCommands.PreviousTrack" Content="&#xE892;" />
75
- <Button Command="MediaCommands.Play" Content="&#xE768;" />
76
- <Button Command="MediaCommands.Pause" Content="&#xE769;" />
77
- <Button Command="MediaCommands.NextTrack" Content="&#xE893;" />
78
- </StackPanel>
79
- </Grid>
80
- </StackPanel>
81
- <VisualStateManager.VisualStateGroups>
82
- <VisualStateGroup x:Name="ControllerStates">
83
- <VisualState x:Name="ControllerHide">
84
- <Storyboard>
85
- <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
86
- <EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,0,0,-85">
87
- <EasingThicknessKeyFrame.EasingFunction>
88
- <ExponentialEase EasingMode="EaseIn" />
89
- </EasingThicknessKeyFrame.EasingFunction>
90
- </EasingThicknessKeyFrame>
91
- </ThicknessAnimationUsingKeyFrames>
92
- </Storyboard>
93
- </VisualState>
94
- <VisualState x:Name="ControllerShow">
95
- <Storyboard>
96
- <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
97
- <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0,0,0,0">
98
- <EasingThicknessKeyFrame.EasingFunction>
99
- <CubicEase EasingMode="EaseIn" />
100
- </EasingThicknessKeyFrame.EasingFunction>
101
- </EasingThicknessKeyFrame>
102
- </ThicknessAnimationUsingKeyFrames>
103
- </Storyboard>
104
- </VisualState>
105
- </VisualStateGroup>
106
- </VisualStateManager.VisualStateGroups>
107
- </Grid>
108
- </Window>
109
- ```
110
-
111
- ```C#
112
- using System;
113
- using System.Windows;
114
- using System.Windows.Input;
115
- using System.Windows.Threading;
116
-
117
- namespace Questions358311
118
- {
119
- public partial class MainWindow : Window
120
- {
121
- private readonly DispatcherTimer hideTimer;
122
- private bool isHide;
123
-
124
- public MainWindow()
125
- {
126
- InitializeComponent();
127
-
128
- hideTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3), };
129
- hideTimer.Tick += (s, e) =>
130
- {
131
- hideTimer.Stop();
132
- isHide = true;
133
- UpdateStates(true);
134
- };
135
- }
136
-
137
- private void UpdateStates(bool useTransitions)
138
- {
139
- if (isHide) VisualStateManager.GoToElementState(grid, "ControllerHide", useTransitions);
140
- else VisualStateManager.GoToElementState(grid, "ControllerShow", useTransitions);
141
- }
142
-
143
- protected override void OnMouseMove(MouseEventArgs e)
144
- {
145
- base.OnMouseMove(e);
146
-
147
- isHide = false;
148
- UpdateStates(true);
149
-
150
- hideTimer.Start();
151
- }
152
- }
153
- }
154
- ```
155
- ![アプリ画像 - コントローラ表示](7b94b3adde3b7e8e10a71a383978bd54.png)
156
- ![アプリ画像 - コントローラ非表示](33104cc2a55552e0ac86a53f4ef637c6.png)
157
-
158
- 本来はボタン等にスタイルを当てていますが、無駄に長くなるので省略。
1
+ > 動画プレイヤーを学習の一環として作ってみようと考えていますが、On/Offできる操作パネルのレイアウト方法で困っています。
2
+
3
+ 私も過去に何度か挑戦しているんですが、なかなか「これが決定版!」というのはできてないんですよねぇ(WinUI 3で`MediaPlayerElement`が使えるようになるんだったら、用済みになりそうというのもあります^^;
4
+ [メディア プレーヤー - Windows apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/apps/design/controls/media-playback)
5
+
6
+
7
+ Baseさんのイメージとはちょっと違うのかな?という気もしますが、
8
+
9
+ > もし他のアイディアもあれば、記載いただけたら嬉しいです。
10
+
11
+ ということなので「しばらくマウス操作がなければ消える」というのはどうでしょう?
12
+ 割と今風?ですし、何もしなくていいので(ユーザー目線で)楽な感じはします。
13
+
14
+ 3秒間ウィンドウ内でマウスが動かなかった場合、下方向にスーッとスライドアウトします。
15
+ マウスが動くとシュッとスライドインします(秒数やイージング具合はお好みで)
16
+
17
+ こだわりポイントはシークバーをわざと見切れるようにして、隠れた状態でも再生位置がわかるようになっているところですw
18
+
19
+ 実際のプロジェクトではカスタムコントロールですが、最低限に簡略化するとこんな感じです。
20
+
21
+ ```xml
22
+ <Window
23
+ x:Class="Questions358311.MainWindow"
24
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
25
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
26
+ Width="800"
27
+ Height="450">
28
+ <Grid
29
+ x:Name="grid"
30
+ Background="Transparent"
31
+ ClipToBounds="True">
32
+ <Grid.Resources>
33
+ <Style TargetType="{x:Type Button}">
34
+ <Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
35
+ <Setter Property="Width" Value="40" />
36
+ <Setter Property="Height" Value="40" />
37
+ </Style>
38
+ </Grid.Resources>
39
+
40
+ <!--<MediaElement />-->
41
+ <!-- MediaElementのかわりにとりあえずImage -->
42
+ <Image Source="https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg" />
43
+
44
+ <StackPanel x:Name="lowerArea" VerticalAlignment="Bottom">
45
+ <StackPanel.Background>
46
+ <LinearGradientBrush MappingMode="RelativeToBoundingBox" StartPoint="0.5,0" EndPoint="0.5,1">
47
+ <GradientStop Offset="1" Color="#CC000000" />
48
+ <GradientStop Color="#00000000" />
49
+ </LinearGradientBrush>
50
+ </StackPanel.Background>
51
+ <ProgressBar
52
+ Height="30"
53
+ Background="#00E6E6E6"
54
+ Foreground="#340034B2"
55
+ Value="50" />
56
+ <Grid>
57
+ <Grid.ColumnDefinitions>
58
+ <ColumnDefinition />
59
+ <ColumnDefinition Width="Auto" />
60
+ <ColumnDefinition />
61
+ </Grid.ColumnDefinitions>
62
+ <StackPanel Orientation="Horizontal">
63
+ <Button Command="MediaCommands.MuteVolume" Content="&#xE767;" />
64
+ <Slider
65
+ Width="125"
66
+ VerticalAlignment="Center"
67
+ IsMoveToPointEnabled="True" />
68
+ </StackPanel>
69
+ <StackPanel
70
+ Grid.Column="1"
71
+ Margin="10"
72
+ HorizontalAlignment="Center"
73
+ Orientation="Horizontal">
74
+ <Button Command="MediaCommands.PreviousTrack" Content="&#xE892;" />
75
+ <Button Command="MediaCommands.Play" Content="&#xE768;" />
76
+ <Button Command="MediaCommands.Pause" Content="&#xE769;" />
77
+ <Button Command="MediaCommands.NextTrack" Content="&#xE893;" />
78
+ </StackPanel>
79
+ </Grid>
80
+ </StackPanel>
81
+ <VisualStateManager.VisualStateGroups>
82
+ <VisualStateGroup x:Name="ControllerStates">
83
+ <VisualState x:Name="ControllerHide">
84
+ <Storyboard>
85
+ <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
86
+ <EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,0,0,-85">
87
+ <EasingThicknessKeyFrame.EasingFunction>
88
+ <ExponentialEase EasingMode="EaseIn" />
89
+ </EasingThicknessKeyFrame.EasingFunction>
90
+ </EasingThicknessKeyFrame>
91
+ </ThicknessAnimationUsingKeyFrames>
92
+ </Storyboard>
93
+ </VisualState>
94
+ <VisualState x:Name="ControllerShow">
95
+ <Storyboard>
96
+ <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="lowerArea" Storyboard.TargetProperty="(FrameworkElement.Margin)">
97
+ <EasingThicknessKeyFrame KeyTime="0:0:0.2" Value="0,0,0,0">
98
+ <EasingThicknessKeyFrame.EasingFunction>
99
+ <CubicEase EasingMode="EaseIn" />
100
+ </EasingThicknessKeyFrame.EasingFunction>
101
+ </EasingThicknessKeyFrame>
102
+ </ThicknessAnimationUsingKeyFrames>
103
+ </Storyboard>
104
+ </VisualState>
105
+ </VisualStateGroup>
106
+ </VisualStateManager.VisualStateGroups>
107
+ </Grid>
108
+ </Window>
109
+ ```
110
+
111
+ ```cs
112
+ using System;
113
+ using System.Windows;
114
+ using System.Windows.Input;
115
+ using System.Windows.Threading;
116
+
117
+ namespace Questions358311
118
+ {
119
+ public partial class MainWindow : Window
120
+ {
121
+ private readonly DispatcherTimer hideTimer;
122
+ private bool isHide;
123
+
124
+ public MainWindow()
125
+ {
126
+ InitializeComponent();
127
+
128
+ hideTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(3), };
129
+ hideTimer.Tick += (s, e) =>
130
+ {
131
+ hideTimer.Stop();
132
+ isHide = true;
133
+ UpdateStates(true);
134
+ };
135
+ }
136
+
137
+ private void UpdateStates(bool useTransitions)
138
+ {
139
+ if (isHide) VisualStateManager.GoToElementState(grid, "ControllerHide", useTransitions);
140
+ else VisualStateManager.GoToElementState(grid, "ControllerShow", useTransitions);
141
+ }
142
+
143
+ protected override void OnMouseMove(MouseEventArgs e)
144
+ {
145
+ base.OnMouseMove(e);
146
+
147
+ isHide = false;
148
+ UpdateStates(true);
149
+
150
+ hideTimer.Start();
151
+ }
152
+ }
153
+ }
154
+ ```
155
+ ![アプリ画像 - コントローラ表示](7b94b3adde3b7e8e10a71a383978bd54.png)
156
+ ![アプリ画像 - コントローラ非表示](33104cc2a55552e0ac86a53f4ef637c6.png)
157
+
158
+ 本来はボタン等にスタイルを当てていますが、無駄に長くなるので省略。
159
159
  コントローラ上にマウスを置きっぱにするとちょっとピクピクします(ちゃんとやろうとするとかなり面倒なので^^;