Mini Kabibi Habibi
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Resources;
using DevExpress.Xpf.DemoBase.Helpers;
using DevExpress.Xpf.DemoBase.Helpers.Internal;
namespace DevExpress.Xpf.LayoutControlDemo {
public class CodeViewer : CodeViewPresenter {
#region Dependency Properties
public static readonly DependencyProperty CurrentItemProperty =
DependencyProperty.Register("CurrentItem", typeof(object), typeof(CodeViewer),
new PropertyMetadata(new PropertyChangedCallback(OnCurrentItemChanged)));
private static void OnCurrentItemChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) {
((CodeViewer)o).OnCurrentItemChanged();
}
#endregion Dependency Properties
private Type _CurrentItemType;
public CodeViewer() {
FontFamily = new FontFamily("Consolas");
FontSize = 13;
}
public object CurrentItem {
get { return (object)GetValue(CurrentItemProperty); }
set { SetValue(CurrentItemProperty, value); }
}
public Type CurrentItemType {
get { return _CurrentItemType; }
private set {
if(CurrentItemType == value)
return;
_CurrentItemType = value;
OnCurrentItemTypeChanged();
}
}
string LoadSourceCode(Type type) {
string resourcePath =
string.Format("/{0};component/Data/{1}{2}",
type.Assembly.FullName.Split(',')[0],
type.Name,
DemoHelper.GetCodeSuffix(type.Assembly));
StreamResourceInfo resource = Application.GetResourceStream(new Uri(resourcePath, UriKind.Relative));
return resource != null ? new StreamReader(resource.Stream).ReadToEnd() : null;
}
void OnCurrentItemChanged() {
CurrentItemType = CurrentItem != null ? CurrentItem.GetType() : null;
}
void OnCurrentItemTypeChanged() {
if(CurrentItemType != null)
CodeText = new CodeLanguageText(DemoHelper.GetDemoLanguage(CurrentItemType.Assembly), LoadSourceCode(CurrentItemType));
else
CodeText = null;
}
}
}