Repository navigation
Expand file tree
/
Copy pathSomeTypeVisualizerUsingViewModel.cs
More file actions
51 lines (41 loc) · 1.9 KB
/
Copy pathSomeTypeVisualizerUsingViewModel.cs
File metadata and controls
51 lines (41 loc) · 1.9 KB
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
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.DebuggerVisualizers;
namespace SimpleExample.DebuggerVisualizer.ReadWriteWithViewModel
{
/// <summary>
/// A Visualizer for SomeType that uses a ViewModel.
/// </summary>
public class SomeTypeVisualizerUsingViewModel : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService,
IVisualizerObjectProvider objectProvider)
{
if (windowService == null)
throw new ArgumentNullException(nameof(windowService));
if (objectProvider == null)
throw new ArgumentNullException(nameof(objectProvider));
// Get the object to display a visualizer for.
// Cast the result of objectProvider.GetObject()
// to the type of the object being visualized.
var data = objectProvider.GetObject() as SimpleExample.SomeType;
// Display your view of the object.
using (var displayForm = new SomeTypeVisualizerWithViewModelForm(data))
{
displayForm.txtFoo.Text = data.Foo;
// Read-Write Approach 1: Using ReplaceObject
//displayForm.OnChange += (sender, newObject) => objectProvider.ReplaceObject(newObject);
// Read-Write Approach 2: Using TransferData
displayForm.OnChange += (sender, newObject) =>
{
var response = objectProvider.TransferObject(newObject) as string;
if (!string.IsNullOrEmpty(response))
{
MessageBox.Show(response, "Response", MessageBoxButtons.OK);
}
};
windowService.ShowDialog(displayForm);
}
}
}
}