blob: ff1b9c8e65e2b318620edd292ca2cf74b3ebd226 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
using System;
using System.Linq;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
{
public class BrushEditorControl : PropertyEditorControl
{
public BrushEditorControl()
{
DefaultStyleKey = typeof (BrushEditorControl);
}
public override void OnApplyTemplate ()
{
base.OnApplyTemplate ();
this.brushBoxButton = GetTemplateChild ("brushBoxButton") as ButtonBase;
this.brushBoxPopup = GetTemplateChild ("brushBoxPopup") as Popup;
if (this.brushBoxButton == null)
throw new InvalidOperationException ($"{nameof(BrushEditorControl)} is missing a child ButtonBase named \"brushBoxButton\"");
if (this.brushBoxPopup == null)
throw new InvalidOperationException ("BrushEditorControl is missing a child Popup named \"brushBoxPopup\"");
this.brushTabs = this.brushBoxPopup.Child?.GetDescendants<BrushTabbedEditorControl>().FirstOrDefault();
this.brushBoxPopup.Opened += (s, e) => {
this.brushTabs?.FocusFirstChild ();
if (DataContext is BrushPropertyViewModel viewModel) {
viewModel.Solid?.ResetInitialColor ();
}
};
this.brushBoxPopup.Closed += (s, e) => {
this.brushBoxButton.Focus ();
};
this.brushBoxPopup.KeyUp += (s, e) => {
if (e.Key == Key.Escape) {
this.brushBoxPopup.IsOpen = false;
}
};
}
private ButtonBase brushBoxButton;
private Popup brushBoxPopup;
private BrushTabbedEditorControl brushTabs;
}
}
|