markus / KCOM / Behaviors / WindowStateBehavior.cs @ a9a82876
이력 | 보기 | 이력해설 | 다운로드 (1.74 KB)
1 | 24c5e56c | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using System.Windows; |
||
7 | |||
8 | namespace KCOM.Behaviors |
||
9 | { |
||
10 | public class CustomWindowStateBehavior : System.Windows.Interactivity.Behavior<System.Windows.Window> |
||
11 | { |
||
12 | protected override void OnAttached() |
||
13 | { |
||
14 | AssociatedObject.StateChanged += AssociatedObject_StateChanged; |
||
15 | base.OnAttached(); |
||
16 | } |
||
17 | |||
18 | private void AssociatedObject_StateChanged(object sender, EventArgs e) |
||
19 | { |
||
20 | if(AssociatedObject.WindowState == WindowState.Maximized) |
||
21 | { |
||
22 | AssociatedObject.WindowState = WindowState.Normal; |
||
23 | AssociatedObject.SetValue(CustomStateProperty, WindowState.Maximized); |
||
24 | } |
||
25 | } |
||
26 | |||
27 | |||
28 | protected override void OnDetaching() |
||
29 | { |
||
30 | AssociatedObject.StateChanged += AssociatedObject_StateChanged; |
||
31 | base.OnDetaching(); |
||
32 | } |
||
33 | |||
34 | public static WindowState GetCustomState(DependencyObject obj) |
||
35 | { |
||
36 | return (WindowState)obj.GetValue(CustomStateProperty); |
||
37 | } |
||
38 | public static void SetCustomState(DependencyObject obj, WindowState value) |
||
39 | { |
||
40 | obj.SetValue(CustomStateProperty, value); |
||
41 | } |
||
42 | |||
43 | public static readonly DependencyProperty CustomStateProperty = DependencyProperty.RegisterAttached("CustomState", typeof(WindowState), |
||
44 | typeof(Window), new FrameworkPropertyMetadata(WindowState.Normal, new PropertyChangedCallback(ApplicationCenterPropertyChanged))); |
||
45 | |||
46 | private static void CustomStatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
||
47 | { |
||
48 | |||
49 | } |
||
50 | |||
51 | } |
||
52 | } |