aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/WpfExtendedToolKit/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/MainWindow.xaml.cs
blob: 49edb97fc8543fe79cedc32e0ee30fcd8bb933d4 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*************************************************************************************

   Toolkit for WPF

   Copyright (C) 2007-2017 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  ***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using System.Reflection;
using Xceed.Wpf.Toolkit.LiveExplorer;
using Xceed.Wpf.Toolkit.LiveExplorer.Core;
using System.Diagnostics;

namespace Xceed.Wpf.Toolkit.LiveExplorer
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    private const string toolkitAssembly = "Xceed.Wpf.Toolkit.LiveExplorer";

    public MainWindow()
    {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler( this.MainWindow_Loaded );

      VersionTextBlock.Text = "Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }


    #region Properties

    #region View

    public static readonly DependencyProperty ViewProperty = DependencyProperty.Register( "View", typeof( DemoView ), typeof( MainWindow ), new UIPropertyMetadata( null, OnViewChanged ) );
    public DemoView View
    {
      get
      {
        return ( DemoView )GetValue( ViewProperty );
      }
      set
      {
        SetValue( ViewProperty, value );
      }
    }

    private static void OnViewChanged( DependencyObject o, DependencyPropertyChangedEventArgs e )
    {
      MainWindow window = o as MainWindow;
      if( window != null )
        window.OnViewChanged( ( DemoView )e.OldValue, ( DemoView )e.NewValue );
    }

    protected virtual void OnViewChanged( DemoView oldValue, DemoView newValue )
    {
      this.InitView();
    }

    #endregion //View

    #endregion //Properties

    #region Event Handler

    void MainWindow_Loaded( object sender, RoutedEventArgs e )
    {
      this.InitView();
    }

    private void OnTreeViewSelectionChanged( object sender, RoutedPropertyChangedEventArgs<Object> e )
    {
      this.UpdateSelectedView( e.NewValue as LiveExplorerTreeViewItem );
    }

    private void UpdateSelectedView( LiveExplorerTreeViewItem treeViewItem )
    {
      if( treeViewItem != null )
      {
        treeViewItem.IsExpanded = true;
        Type type = treeViewItem.SampleType;
        if( type != null )
        {
          string name = type.FullName;

          Assembly assembly = Assembly.Load( toolkitAssembly );
          Type sampleType = assembly.GetType( name );

          this.View = ( DemoView )Activator.CreateInstance( sampleType );
        }
      }
    }

    private void Hyperlink_RequestNavigate( object sender, System.Windows.Navigation.RequestNavigateEventArgs e )
    {
      Process.Start( new ProcessStartInfo( e.Uri.AbsoluteUri ) );
      e.Handled = true;
    }

    private void Image_MouseLeftButtonDown( object sender, MouseButtonEventArgs e )
    {
      //When the user clicks the Xceed logo on the top left.
      //
    }

    #endregion //EventHandler

    #region Methods

    private void InitView()
    {
      if( ( _flowDocumentDesc != null ) && ( this.View != null) )
      {
        _flowDocumentDesc.Blocks.Clear();
        if( this.View.Description != null )
        {
          _flowDocumentDesc.Blocks.Add( this.View.Description );
        }
      }
      if( _contentScrollViewer != null )
      {
        _contentScrollViewer.ScrollToHome();
      }
    }

    #endregion

  }
}