Files
BeWoPlaner/Controls/Controls/BSGridControl.cs
2016-06-27 01:45:38 +02:00

170 lines
6.1 KiB
C#

using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using DevExpress.Xpf.Grid;
namespace BeWo.Controls
{
[DefaultProperty("Content")]
[ContentProperty("Content")]
public class BSGridControl : Control
{
public static readonly DependencyProperty ContentProperty;
public static readonly DependencyProperty GridControlProperty;
public static readonly DependencyProperty OptionsContentProperty;
public static readonly DependencyProperty OptionsExpandedProperty;
// public static readonly DependencyProperty CurrentThemeNameProperty;
static BSGridControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(BSGridControl), new FrameworkPropertyMetadata(typeof(BSGridControl)));
ContentProperty = DependencyProperty.Register("Content", typeof(FrameworkElement), typeof(BSGridControl), new FrameworkPropertyMetadata(null));
// CurrentThemeNameProperty = DependencyProperty.RegisterAttached("CurrentThemeName", typeof(string), typeof(BSGridControl), new FrameworkPropertyMetadata("Emerald", FrameworkPropertyMetadataOptions.Inherits, OnCurrentThemeNamePropertyChanged));
OptionsContentProperty = DependencyProperty.Register("OptionsContent", typeof(FrameworkElement), typeof(BSGridControl), new FrameworkPropertyMetadata(null));
GridControlProperty = DependencyProperty.Register("GridControl", typeof(GridControl), typeof(BSGridControl), new FrameworkPropertyMetadata(null));
OptionsExpandedProperty = DependencyProperty.Register("OptionsExpanded", typeof(bool), typeof(BSGridControl), new FrameworkPropertyMetadata(true));
}
// public static string GetCurrentThemeName(DependencyObject obj)
// {
// return (string)obj.GetValue(CurrentThemeNameProperty);
// }
// public static void SetCurrentThemeName(DependencyObject obj, string value)
// {
// obj.SetValue(CurrentThemeNameProperty, value);
// }
// public static void OnCurrentThemeNamePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
// {
// BSGridControl dm = obj as BSGridControl;
// if (dm != null) dm.OnCurrentThemeNameChanged();
// }
public BSGridControl()
{
this.CreateGridControl();
}
// public virtual bool AllThemesEnabled { get { return true; } }
// public bool OptionsExpanded
// {
// get { return (bool)GetValue(OptionsExpandedProperty); }
// set { SetValue(OptionsExpandedProperty, value); }
// }
public FrameworkElement Content
{
get
{
return (FrameworkElement)this.GetValue(ContentProperty);
}
set
{
this.SetValue(ContentProperty, value);
}
}
// public FrameworkElement OptionsContent
// {
// get { return (FrameworkElement)GetValue(OptionsContentProperty); }
// set { SetValue(OptionsContentProperty, value); }
// }
public GridControl GridControl
{
get
{
return (GridControl)this.GetValue(GridControlProperty);
}
set
{
this.SetValue(GridControlProperty, value);
}
}
private void CreateGridControl()
{
GridControl gc = new GridControl();
this.GridControl = gc;
}
// public override void OnApplyTemplate()
// {
// base.OnApplyTemplate();
// if (GridControl != null) return;
// VisualTreeEnumerator en = new VisualTreeEnumerator(Content);
// while (en.MoveNext())
// {
// if (en.Current is GridControl)
// {
// GridControl = (GridControl)en.Current;
// RegisterDemoBaseThemes();
// OnCurrentThemeNameChanged();
// break;
// }
// }
// }
// public virtual void ShowOptions()
// {
// OptionsExpanded = true;
// }
// public virtual void HideOptions()
// {
// OptionsExpanded = false;
// }
// public string CurrentThemeName
// {
// get { return (string)GetValue(CurrentThemeNameProperty); }
// set { SetValue(CurrentThemeNameProperty, value); }
// }
// protected virtual Theme CreateTheme(string themeName)
// {
// ResourceDictionary rd = XamlLoaderHelper<ResourceDictionary>.LoadFromApplicationResources(string.Format(@"\Themes\{0}.xaml", themeName));
// if (rd == null)
// return new Theme() { Source = themeName, LoadFromResources = true };
// return rd[themeName] as Theme;
// }
// protected virtual Theme CreateTheme()
// {
// return CreateTheme(CurrentThemeName);
// }
// void RegisterDemoBaseTheme(string themeName)
// {
// if (DemoContent == null)
// return;
// ActionsList list = ThemeManager.GetActions(DemoContent);
// if (list == null)
// list = new ActionsList();
// else
// list = new ActionsList(list);
// list.Add(new AddResourcesThemeAction()
// {
// ThemeName = themeName,
// Resources = XamlLoaderHelper<ResourceDictionary>.LoadFromApplicationResources(string.Format(@"\Themes\{0}.xaml", themeName))
// });
// ThemeManager.SetActions(DemoContent, list);
// }
// protected virtual void RegisterDemoBaseThemes()
// {
// ThemeManager.SetCreateNew(this, true);
// RegisterDemoBaseTheme("Emerald");
// RegisterDemoBaseTheme("Azure");
// }
// protected virtual void OnCurrentThemeNameChanged()
// {
// if (GridControl == null) return;
// GridControl.Theme = CreateTheme();
// }
}
}