blob: 097eab7952be113762e58a43a1e5c2014529767b (
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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Windows
{
internal partial class CollectionEditorWindow
: WindowEx, IPropertiesHost
{
public CollectionEditorWindow (IEnumerable<ResourceDictionary> mergedResources)
{
Resources.MergedDictionaries.AddItems (mergedResources);
InitializeComponent ();
DataContextChanged += OnDataContextChanged;
}
protected override void OnClosing (CancelEventArgs e)
{
if (DataContext is CollectionPropertyViewModel vm) {
if (!DialogResult.HasValue || !DialogResult.Value)
vm.CancelCommand.Execute (null);
vm.TypeRequested -= OnTypeRequested;
}
base.OnClosing (e);
}
private void OnDataContextChanged (object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is CollectionPropertyViewModel oldVm)
oldVm.TypeRequested -= OnTypeRequested;
if (e.NewValue is CollectionPropertyViewModel vm)
vm.TypeRequested += OnTypeRequested;
}
private void OnTypeRequested (object sender, TypeRequestedEventArgs args)
{
args.SelectedType = TypeSelectorWindow.RequestType (this, ((CollectionPropertyViewModel)DataContext).AssignableTypes);
}
private void OnOkClick (object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void OnCancelClick (object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
}
|