Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/VB/LayoutControlDemo.Wpf/Controls/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WPF/VB/LayoutControlDemo.Wpf/Controls/CodeViewer.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Imports System.Windows.Resources
Imports DevExpress.Xpf.DemoBase.Helpers
Imports DevExpress.Xpf.DemoBase.Helpers.Internal

Namespace DevExpress.Xpf.LayoutControlDemo
	Public Class CodeViewer
		Inherits CodeViewPresenter
		#Region "Dependency Properties"

		Public Shared ReadOnly CurrentItemProperty As DependencyProperty = DependencyProperty.Register("CurrentItem", GetType(Object), GetType(CodeViewer), New PropertyMetadata(New PropertyChangedCallback(AddressOf OnCurrentItemChanged)))

		Private Shared Sub OnCurrentItemChanged(ByVal o As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
			CType(o, CodeViewer).OnCurrentItemChanged()
		End Sub

		#End Region ' Dependency Properties

		Private _CurrentItemType As Type

		Public Sub New()
			FontFamily = New FontFamily("Consolas")
			FontSize = 13
		End Sub

		Public Property CurrentItem() As Object
			Get
				Return CObj(GetValue(CurrentItemProperty))
			End Get
			Set(ByVal value As Object)
				SetValue(CurrentItemProperty, value)
			End Set
		End Property
		Public Property CurrentItemType() As Type
			Get
				Return _CurrentItemType
			End Get
			Private Set(ByVal value As Type)
				If CurrentItemType Is value Then
					Return
				End If
				_CurrentItemType = value
				OnCurrentItemTypeChanged()
			End Set
		End Property

		Private Function LoadSourceCode(ByVal type As Type) As String
			Dim resourcePath As String = String.Format("/{0};component/Data/{1}{2}", type.Assembly.FullName.Split(","c)(0), type.Name, DemoHelper.GetCodeSuffix(type.Assembly))
			Dim resource As StreamResourceInfo = Application.GetResourceStream(New Uri(resourcePath, UriKind.Relative))
			Return If(resource IsNot Nothing, New StreamReader(resource.Stream).ReadToEnd(), Nothing)
		End Function
		Private Sub OnCurrentItemChanged()
			CurrentItemType = If(CurrentItem IsNot Nothing, CurrentItem.GetType(), Nothing)
		End Sub
		Private Sub OnCurrentItemTypeChanged()
			If CurrentItemType IsNot Nothing Then
				CodeText = New CodeLanguageText(DemoHelper.GetDemoLanguage(CurrentItemType.Assembly), LoadSourceCode(CurrentItemType))
			Else
				CodeText = Nothing
			End If
		End Sub
	End Class
End Namespace