1: public class ViewModel
2: {
3: public ViewModel()
4: {
5: Extents = new Extents();
6: PreviousExtent = new DelegateCommand(MovePreviousExtent, extent => Extents.HasPreviousExtent);
7: NextExtent = new DelegateCommand(MoveNextExtent, extent => Extents.HasNextExtent);
8: IsNewExtent = true;
9: }
10:
11: private Map _map;
12:
13: public Map Map
14: {
15: get { return _map; }
16: set
17: {
18: UnsubscribeMapEvents(_map);
19: SubscribeMapEvents(value);
20: _map = value;
21: }
22: }
23:
24: public DelegateCommand PreviousExtent { get; private set; }
25: public DelegateCommand NextExtent { get; private set; }
26:
27: private bool IsNewExtent { get; set; }
28: private Extents Extents { get; set; }
29:
30: private void MovePreviousExtent(object obj)
31: {
32: // This extent should not be put onto the Extents stack.
33: IsNewExtent = false;
34: Map.ZoomTo(Extents.PreviousExtent);
35: }
36:
37: private void MoveNextExtent(object obj)
38: {
39: // This extent should not be put onto the Extents stack.
40: IsNewExtent = false;
41: Map.ZoomTo(Extents.NextExtent);
42: }
43:
44: private void UnsubscribeMapEvents(Map map)
45: {
46: if (map == null) return;
47: map.ExtentChanged -= Map_ExtentChanged;
48: }
49:
50: private void SubscribeMapEvents(Map map)
51: {
52: if (map == null) return;
53: map.ExtentChanged += Map_ExtentChanged;
54: }
55:
56: private void Map_ExtentChanged(object sender, ExtentEventArgs e)
57: {
58: // Only add the extent if it is "new" ie: Not a Previous or Next extent
59: if (IsNewExtent)
60: {
61: Extents.Add(e.NewExtent);
62: }
63: IsNewExtent = true;
64: PreviousExtent.RaiseCanExecuteChanged();
65: NextExtent.RaiseCanExecuteChanged();
66: }
67: }