blob: 1a0399e3986257f2c73992afd4648bb48b4d3625 (
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
51
52
53
54
55
56
57
|
using System.Windows.Controls;
using Xamarin.PropertyEditing.Drawing;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
{
public class BrushEditorControl : PropertyEditorControl
{
public BrushEditorControl()
{
DefaultStyleKey = typeof (BrushEditorControl);
}
BrushPropertyViewModel ViewModel => DataContext as BrushPropertyViewModel;
TabControl tabs;
TabItem noBrushTab;
TabItem solidColorTab;
public override void OnApplyTemplate ()
{
base.OnApplyTemplate ();
tabs = GetTemplateChild ("brushTabs") as TabControl;
noBrushTab = GetTemplateChild ("noBrushTab") as TabItem;
solidColorTab = GetTemplateChild ("solidColorTab") as TabItem;
if (ViewModel.Value == null) {
tabs.SelectedItem = noBrushTab;
}
else if (ViewModel.Value is CommonSolidBrush solidBrush) {
tabs.SelectedItem = solidColorTab;
}
tabs.SelectionChanged += (s, e) => {
if (ViewModel == null) return;
if (tabs.Items[tabs.SelectedIndex] is TabItem tab) {
StorePreviousBrush ();
if (tab == noBrushTab) {
ViewModel.Value = null;
}
else if (tab == solidColorTab) {
ViewModel.Value = ViewModel.PreviousSolidBrush ?? new CommonSolidBrush (new CommonColor (0, 0, 0));
}
}
};
}
void StorePreviousBrush()
{
if (ViewModel == null) return;
if (ViewModel.Value is CommonSolidBrush solidBrush) {
ViewModel.PreviousSolidBrush = solidBrush;
}
}
}
}
|