markus / KCOM / Extensions / WindowHelper.cs @ 503cb09e
이력 | 보기 | 이력해설 | 다운로드 (2.69 KB)
1 | aff63364 | 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.Interactivity; |
||
7 | |||
8 | namespace KCOM |
||
9 | { |
||
10 | public static class WindowHelper |
||
11 | { |
||
12 | public static void ShowCenter(this System.Windows.Controls.ContentControl window) |
||
13 | { |
||
14 | SetApplicationCenterBehavior(window); |
||
15 | |||
16 | if (window is System.Windows.Window) |
||
17 | { |
||
18 | (window as System.Windows.Window).Show(); |
||
19 | } |
||
20 | else if (window is Telerik.Windows.Controls.RadWindow) |
||
21 | { |
||
22 | (window as System.Windows.Window).Show(); |
||
23 | } |
||
24 | else |
||
25 | { |
||
26 | throw new Exception("window Type is System.Windows.Window or Telerik.Windows.Controls.RadWindow"); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | public static bool? ShowDialogCenter(this System.Windows.Window window) |
||
31 | { |
||
32 | if (window is System.Windows.Window) |
||
33 | { |
||
34 | SetApplicationCenterBehavior(window); |
||
35 | |||
36 | return window.ShowDialog(); |
||
37 | } |
||
38 | else |
||
39 | { |
||
40 | throw new Exception("window Type is System.Windows.Window"); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public static void ShowDialogCenter(this Telerik.Windows.Controls.RadWindow window) |
||
45 | { |
||
46 | if (window is Telerik.Windows.Controls.RadWindow) |
||
47 | { |
||
48 | SetApplicationCenterBehavior(window); |
||
49 | window.ShowDialog(); |
||
50 | } |
||
51 | else |
||
52 | { |
||
53 | throw new Exception("window Type is Telerik.Windows.Controls.RadWindow"); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | private static void SetApplicationCenterBehavior(System.Windows.Controls.ContentControl window) |
||
58 | { |
||
59 | if (window.GetType().GetProperty("Owner").GetValue(window) == null) |
||
60 | { |
||
61 | window.GetType().GetProperty("Owner").SetValue(window, App.Current.Windows.Cast<System.Windows.Window>().FirstOrDefault()); |
||
62 | } |
||
63 | |||
64 | if (Interaction.GetBehaviors(window).Count(f => f is KCOM.Behaviors.WindowBehavior) == 0) |
||
65 | { |
||
66 | KCOM.Behaviors.WindowBehavior windowBehavior = new Behaviors.WindowBehavior(); |
||
67 | |||
68 | windowBehavior.SetValue(KCOM.Behaviors.WindowBehavior.ApplicationCenterProperty, true); |
||
69 | |||
70 | //windowBehavior.SetBinding(KCOM.Behaviors.WindowBehavior.ApplicationCenterProperty, new Binding() |
||
71 | //{ |
||
72 | // ElementName = "_uc", |
||
73 | // Path = new PropertyPath("SelectedItems"), |
||
74 | // Mode = BindingMode.TwoWay |
||
75 | //}); |
||
76 | |||
77 | Interaction.GetBehaviors(window).Add(windowBehavior); |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |