@@ -24,10 +24,12 @@ public partial class EmbedDeasktopView : Window
24
24
private Point anchorPoint ;
25
25
private readonly KeyboardHook _hook ;
26
26
private readonly List < Key > keys = new List < Key > ( ) ;
27
+ private MainVM mainVM ;
27
28
28
29
public EmbedDeasktopView ( )
29
30
{
30
31
InitializeComponent ( ) ;
32
+ mainVM = DataContext as MainVM ;
31
33
desktopWorkingArea = SystemParameters . WorkArea ;
32
34
Loaded += EmbedDeasktopView_Loaded ;
33
35
Closing += EmbedDeasktopView_Closing ;
@@ -38,13 +40,14 @@ public EmbedDeasktopView()
38
40
39
41
private void OnHookKeyUp ( object sender , HookEventArgs e )
40
42
{
43
+ if ( ! mainVM . IsEmbedded ) return ;
41
44
SetKeyUp ( e . Key ) ;
42
- Thread . Sleep ( 300 ) ;
43
45
KeyDownPanel . Visibility = Visibility . Collapsed ;
44
46
}
45
47
46
48
private void OnHookKeyDown ( object sender , HookEventArgs e )
47
49
{
50
+ if ( ! mainVM . IsEmbedded ) return ;
48
51
SetKeyDown ( e . Key ) ;
49
52
if ( IsKeyDown ( Key . PrintScreen ) )
50
53
{
@@ -191,11 +194,19 @@ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
191
194
#endregion
192
195
public void ExitEmbedded ( )
193
196
{
194
- Width = 110 ;
197
+ if ( ToggleButtonMini . IsChecked == true )
198
+ Width = 30 ;
199
+ else
200
+ Width = 120 ;
195
201
Height = desktopWorkingArea . Height / 2 ;
196
202
Left = desktopWorkingArea . Width - Width ;
197
203
Top = desktopWorkingArea . Height / 2 - ( Height / 2 ) ;
198
204
}
205
+ public void OepnEmbedded ( )
206
+ {
207
+ if ( mainVM . IsEmbedded ) return ;
208
+
209
+ }
199
210
#region 窗体动画
200
211
private void ToggleButtonMini_Checked ( object sender , RoutedEventArgs e )
201
212
{
@@ -210,24 +221,30 @@ private void ToggleButtonMini_Checked(object sender, RoutedEventArgs e)
210
221
var heightAnimation = new DoubleAnimation
211
222
{
212
223
Name = "heightMini" ,
224
+ From = desktopWorkingArea . Height / 2 ,
213
225
To = 60 ,
214
226
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
215
- EasingFunction = easeFunction
227
+ EasingFunction = easeFunction ,
228
+ } ;
229
+ heightAnimation . Completed += delegate
230
+ {
231
+ BeginAnimation ( HeightProperty , null ) ;
216
232
} ;
217
233
var widthAnimation = new DoubleAnimation
218
234
{
219
235
Name = "widthMini" ,
236
+ From = 120 ,
220
237
To = 30 ,
221
238
Duration = new Duration ( TimeSpan . FromSeconds ( 0.51 ) ) ,
222
- EasingFunction = easeFunction
239
+ EasingFunction = easeFunction ,
223
240
} ;
224
241
widthAnimation . Completed += delegate
225
242
{
226
- this . Left = desktopWorkingArea . Width - this . Width ;
243
+ Left = desktopWorkingArea . Width - this . Width ;
244
+ BeginAnimation ( WidthProperty , null ) ;
227
245
} ;
228
-
229
- this . BeginAnimation ( HeightProperty , heightAnimation ) ;
230
- this . BeginAnimation ( WidthProperty , widthAnimation ) ;
246
+ BeginAnimation ( HeightProperty , heightAnimation ) ;
247
+ BeginAnimation ( WidthProperty , widthAnimation ) ;
231
248
}
232
249
catch ( Exception ex )
233
250
{
@@ -248,23 +265,30 @@ private void UnToggleButtonMini_Checked(object sender, RoutedEventArgs e)
248
265
} ;
249
266
var widthAnimation = new DoubleAnimation
250
267
{
268
+ From = 30 ,
251
269
To = 120 ,
252
270
Duration = new Duration ( TimeSpan . FromSeconds ( 0.01 ) ) ,
253
- EasingFunction = easeFunction
271
+ EasingFunction = easeFunction ,
254
272
} ;
255
273
widthAnimation . Completed += delegate
256
274
{
257
- this . Left = desktopWorkingArea . Width - this . Width ;
275
+ Left = desktopWorkingArea . Width - this . Width ;
276
+ BeginAnimation ( WidthProperty , null ) ;
258
277
} ;
259
278
260
279
var heightAnimation = new DoubleAnimation
261
280
{
281
+ From = 60 ,
262
282
To = desktopWorkingArea . Height / 2 ,
263
283
Duration = new Duration ( TimeSpan . FromSeconds ( 0.5 ) ) ,
264
- EasingFunction = easeFunction
284
+ EasingFunction = easeFunction ,
285
+ } ;
286
+ heightAnimation . Completed += delegate
287
+ {
288
+ BeginAnimation ( HeightProperty , null ) ;
265
289
} ;
266
- this . BeginAnimation ( WidthProperty , widthAnimation ) ;
267
- this . BeginAnimation ( HeightProperty , heightAnimation ) ;
290
+ BeginAnimation ( WidthProperty , widthAnimation ) ;
291
+ BeginAnimation ( HeightProperty , heightAnimation ) ;
268
292
}
269
293
catch ( Exception ex )
270
294
{
@@ -278,8 +302,7 @@ private void UnToggleButtonMini_Checked(object sender, RoutedEventArgs e)
278
302
279
303
private void myNotifyIcon_TrayLeftMouseUp ( object sender , RoutedEventArgs e )
280
304
{
281
- var vm = DataContext as MainVM ;
282
- if ( vm == null && vm . IsEmbedded ) return ;
305
+ if ( mainVM . IsEmbedded ) return ;
283
306
Show ( ) ;
284
307
Activate ( ) ;
285
308
Focus ( ) ;
0 commit comments