aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/WpfExtendedToolKit/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit.LiveExplorer/DemoView.cs
blob: 3df8218c76fe29633804be2f06fd0497d7ebfb88 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*************************************************************************************

   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.Controls;
using System.Windows;
using System.IO;
using System.Windows.Documents;
using System.Diagnostics;

namespace Xceed.Wpf.Toolkit.LiveExplorer
{
  public class DemoView : ContentControl
  {
    #region Members

    readonly string _applicationPath = String.Empty;
    const string _samplesFolderName = "Samples";

    #endregion //Members

    #region Properties

    #region CSharpText

    public static readonly DependencyProperty CSharpTextProperty = DependencyProperty.Register( "CSharpText", typeof( string ), typeof( DemoView ), new UIPropertyMetadata( null ) );
    public string CSharpText
    {
      get
      {
        return ( string )GetValue( CSharpTextProperty );
      }
      set
      {
        SetValue( CSharpTextProperty, value );
      }
    }

    #endregion //CSharpText

    #region Description

    public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register( "Description", typeof( Paragraph ), typeof( DemoView ), new UIPropertyMetadata( null ) );
    public Paragraph Description
    {
      get
      {
        return ( Paragraph )GetValue( DescriptionProperty );
      }
      set
      {
        SetValue( DescriptionProperty, value );
      }
    }

    #endregion //Description

    #region Title

    public static readonly DependencyProperty TitleProperty = DependencyProperty.Register( "Title", typeof( string ), typeof( DemoView ), new UIPropertyMetadata( null ) );
    public string Title
    {
      get
      {
        return ( string )GetValue( TitleProperty );
      }
      set
      {
        SetValue( TitleProperty, value );
      }
    }

    #endregion // Title

    #region VerticalScrollbarVisibility

    public static readonly DependencyProperty VerticalScrollBarVisibilityProperty = DependencyProperty.Register( "VerticalScrollBarVisibility", typeof( ScrollBarVisibility ), typeof( DemoView ), new UIPropertyMetadata( ScrollBarVisibility.Auto ) );
    public ScrollBarVisibility VerticalScrollBarVisibility
    {
      get
      {
        return ( ScrollBarVisibility )GetValue( VerticalScrollBarVisibilityProperty );
      }
      set
      {
        SetValue( VerticalScrollBarVisibilityProperty, value );
      }
    }

    #endregion

    #region XamlText

    public static readonly DependencyProperty XamlTextProperty = DependencyProperty.Register( "XamlText", typeof( string ), typeof( DemoView ), new UIPropertyMetadata( null ) );
    public string XamlText
    {
      get
      {
        return ( string )GetValue( XamlTextProperty );
      }
      set
      {
        SetValue( XamlTextProperty, value );
      }
    }

    #endregion // XamlText

    #endregion //Properties

    #region Constructors

    static DemoView()
    {
    }

    public DemoView()
    {
      _applicationPath = Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location );
    }

    #endregion //Constructors

    #region Base Class Overrides

    protected override void OnContentChanged( object oldContent, object newContent )
    {
      base.OnContentChanged( oldContent, newContent );
      //the parent of the content will be the View
      this.UpdateContentCode( ( newContent as FrameworkElement ).Parent );
    }

    #endregion //Base Class Overrides

    #region Methods

    private void UpdateContentCode( object newContent )
    {
      //get the type of the content loaded in the ContentRegion
      var type = newContent.GetType();
      //grab only the name of the content which will correspond to the name of the file to load
      var viewName = type.FullName.Substring( type.FullName.LastIndexOf( "." ) + 1 );
      //get the module name
      var moduleName = type.Module.Name.Replace( ".dll", String.Empty );

      this.SetText( viewName, moduleName );
    }

    private void SetText( string viewName, string moduleName )
    {
      this.SetCSharpText( viewName, moduleName );
      this.SetXamlText( viewName, moduleName );
    }

    private void SetCSharpText( string viewName, string moduleName )
    {
      //now we need to append the file extension
      Uri uri = new Uri( string.Format( "/CodeFiles/{0}.xaml.txt", viewName ), UriKind.Relative );
      try
      {
        var streamInfo = Application.GetResourceStream( uri );
        using( StreamReader sr = new StreamReader( streamInfo.Stream ) )
        {
          this.XamlText = sr.ReadToEnd();
        }
      }
      catch { }
    }

    private void SetXamlText( string viewName, string moduleName )
    {
      //now we need to append the file extension
      Uri uri = new Uri( string.Format( "/CodeFiles/{0}.xaml.cs.txt", viewName ), UriKind.Relative );
      try
      {
        var streamInfo = Application.GetResourceStream( uri );
        using( StreamReader sr = new StreamReader( streamInfo.Stream ) )
        {
          this.CSharpText = sr.ReadToEnd();
        }
      }
      catch { }
    }

    private string GetFilePath( string moduleName, string fileName )
    {
      return Path.Combine( _applicationPath, _samplesFolderName, fileName );
    }

    private static string ReadFileText( string filePath )
    {
      string text = String.Empty;
      if( File.Exists( filePath ) )
        text = File.ReadAllText( filePath );
      return text;
    }

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

    #endregion // Methods

  }
}