mirror of
https://github.com/VitalickS/BrightSharp.Toolkit.git
synced 2026-03-21 02:21:15 +00:00
Initial
This commit is contained in:
140
BrightSharp/Extensions/MarkupExtensionProperties.cs
Normal file
140
BrightSharp/Extensions/MarkupExtensionProperties.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace BrightSharp.Extensions
|
||||
{
|
||||
public static class MarkupExtensionProperties
|
||||
{
|
||||
public static CornerRadius GetCornerRadius(DependencyObject obj)
|
||||
{
|
||||
return (CornerRadius)obj.GetValue(CornerRadiusProperty);
|
||||
}
|
||||
public static void SetCornerRadius(DependencyObject obj, CornerRadius value)
|
||||
{
|
||||
obj.SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
public static object GetHeader(DependencyObject obj)
|
||||
{
|
||||
return obj.GetValue(HeaderProperty);
|
||||
}
|
||||
public static void SetHeader(DependencyObject obj, object value)
|
||||
{
|
||||
obj.SetValue(HeaderProperty, value);
|
||||
}
|
||||
public static object GetLeadingElement(DependencyObject obj)
|
||||
{
|
||||
return obj.GetValue(CornerRadiusProperty);
|
||||
}
|
||||
public static void SetLeadingElement(DependencyObject obj, object value)
|
||||
{
|
||||
obj.SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
public static object GetTrailingElement(DependencyObject obj)
|
||||
{
|
||||
return obj.GetValue(CornerRadiusProperty);
|
||||
}
|
||||
public static void SetTrailingElement(DependencyObject obj, object value)
|
||||
{
|
||||
obj.SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
public static object GetIcon(DependencyObject obj)
|
||||
{
|
||||
return obj.GetValue(IconProperty);
|
||||
}
|
||||
public static void SetIcon(DependencyObject obj, object value)
|
||||
{
|
||||
obj.SetValue(IconProperty, value);
|
||||
}
|
||||
public static void SetHeaderHeight(DependencyObject obj, double value)
|
||||
{
|
||||
obj.SetValue(HeaderHeightProperty, value);
|
||||
}
|
||||
public static double GetHeaderHeight(DependencyObject obj)
|
||||
{
|
||||
return (double)obj.GetValue(HeaderHeightProperty);
|
||||
}
|
||||
|
||||
public static void SetHeaderVerticalAlignment(DependencyObject obj, VerticalAlignment value)
|
||||
{
|
||||
obj.SetValue(HeaderVerticalAlignmentProperty, value);
|
||||
}
|
||||
public static VerticalAlignment GetHeaderVerticalAlignment(DependencyObject obj)
|
||||
{
|
||||
return (VerticalAlignment)obj.GetValue(HeaderVerticalAlignmentProperty);
|
||||
}
|
||||
public static void SetHeaderHorizontalAlignment(DependencyObject obj, HorizontalAlignment value)
|
||||
{
|
||||
obj.SetValue(HeaderHorizontalAlignmentProperty, value);
|
||||
}
|
||||
public static HorizontalAlignment GetHeaderHorizontalAlignment(DependencyObject obj)
|
||||
{
|
||||
return (HorizontalAlignment)obj.GetValue(HeaderHorizontalAlignmentProperty);
|
||||
}
|
||||
public static void SetSpecialHeight(DependencyObject obj, double value)
|
||||
{
|
||||
obj.SetValue(SpecialHeightProperty, value);
|
||||
}
|
||||
public static double GetSpecialHeight(DependencyObject obj)
|
||||
{
|
||||
return (double)obj.GetValue(SpecialHeightProperty);
|
||||
}
|
||||
public static void SetSpecialWidth(DependencyObject obj, double value)
|
||||
{
|
||||
obj.SetValue(SpecialWidthProperty, value);
|
||||
}
|
||||
public static double GetSpecialWidth(DependencyObject obj)
|
||||
{
|
||||
return (double)obj.GetValue(SpecialWidthProperty);
|
||||
}
|
||||
public static Dock GetDocking(DependencyObject obj)
|
||||
{
|
||||
return (Dock)obj.GetValue(DockingProperty);
|
||||
}
|
||||
public static void SetDocking(DependencyObject obj, Dock value)
|
||||
{
|
||||
obj.SetValue(DockingProperty, value);
|
||||
}
|
||||
public static Thickness GetHeaderPadding(DependencyObject obj)
|
||||
{
|
||||
return (Thickness)obj.GetValue(HeaderPaddingProperty);
|
||||
}
|
||||
public static void SetHeaderPadding(DependencyObject obj, Thickness value)
|
||||
{
|
||||
obj.SetValue(HeaderPaddingProperty, value);
|
||||
}
|
||||
public static bool GetIsDragHelperVisible(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(IsDragHelperVisibleProperty);
|
||||
}
|
||||
public static void SetIsDragHelperVisible(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(IsDragHelperVisibleProperty, value);
|
||||
}
|
||||
public static Brush GetSpecialBrush(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(SpecialBrushProperty);
|
||||
}
|
||||
public static void SetSpecialBrush(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(SpecialBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SpecialBrushProperty = DependencyProperty.RegisterAttached("SpecialBrush", typeof(Brush), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty IsDragHelperVisibleProperty = DependencyProperty.RegisterAttached("IsDragHelperVisible", typeof(bool), typeof(MarkupExtensionProperties), new FrameworkPropertyMetadata(true));
|
||||
public static readonly DependencyProperty HeaderPaddingProperty = DependencyProperty.RegisterAttached("HeaderPadding", typeof(Thickness), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached("CornerRadius", typeof(CornerRadius), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty LeadingElementProperty = DependencyProperty.RegisterAttached("LeadingElement", typeof(object), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty TrailingElementProperty = DependencyProperty.RegisterAttached("TrailingElement", typeof(object), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty HeaderProperty = DependencyProperty.RegisterAttached("Header", typeof(object), typeof(MarkupExtensionProperties), new FrameworkPropertyMetadata(null));
|
||||
public static readonly DependencyProperty DockingProperty = DependencyProperty.RegisterAttached("Docking", typeof(Dock), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty IconProperty = DependencyProperty.RegisterAttached("Icon", typeof(object), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.RegisterAttached("HeaderHeight", typeof(double), typeof(MarkupExtensionProperties), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty HeaderVerticalAlignmentProperty = DependencyProperty.RegisterAttached("HeaderVerticalAlignment", typeof(VerticalAlignment), typeof(MarkupExtensionProperties), new PropertyMetadata(VerticalAlignment.Center));
|
||||
public static readonly DependencyProperty HeaderHorizontalAlignmentProperty = DependencyProperty.RegisterAttached("HeaderHorizontalAlignment", typeof(HorizontalAlignment), typeof(MarkupExtensionProperties), new PropertyMetadata(HorizontalAlignment.Left));
|
||||
public static readonly DependencyProperty SpecialHeightProperty = DependencyProperty.RegisterAttached("SpecialHeight", typeof(double), typeof(MarkupExtensionProperties), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
|
||||
public static readonly DependencyProperty SpecialWidthProperty = DependencyProperty.RegisterAttached("SpecialWidth", typeof(double), typeof(MarkupExtensionProperties), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
72
BrightSharp/Extensions/WpfExtensions.cs
Normal file
72
BrightSharp/Extensions/WpfExtensions.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
|
||||
namespace BrightSharp.Extensions
|
||||
{
|
||||
public static class WpfExtensions
|
||||
{
|
||||
public static DependencyObject GetParent(this DependencyObject obj, bool useLogicalTree = false)
|
||||
{
|
||||
if (!useLogicalTree && (obj is Visual || obj is Visual3D))
|
||||
return VisualTreeHelper.GetParent(obj) ?? LogicalTreeHelper.GetParent(obj);
|
||||
else
|
||||
return LogicalTreeHelper.GetParent(obj);
|
||||
}
|
||||
public static IEnumerable<T> Ancestors<T>(this DependencyObject obj, bool useLogicalTree = false) where T : DependencyObject
|
||||
{
|
||||
if (obj == null) yield break;
|
||||
|
||||
var x = GetParent(obj, useLogicalTree);
|
||||
|
||||
while (x != null && !(x is T))
|
||||
{
|
||||
x = GetParent(x, useLogicalTree);
|
||||
}
|
||||
if (x != null)
|
||||
yield return x as T;
|
||||
else
|
||||
yield break;
|
||||
foreach (var item in Ancestors<T>(x, useLogicalTree))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
public static T FindAncestor<T>(this DependencyObject obj) where T : DependencyObject
|
||||
{
|
||||
return Ancestors<T>(obj).FirstOrDefault();
|
||||
}
|
||||
public static Panel GetItemsPanel(DependencyObject itemsControl)
|
||||
{
|
||||
if (itemsControl is Panel) return (Panel)itemsControl;
|
||||
ItemsPresenter itemsPresenter = GetVisualChild<ItemsPresenter>(itemsControl);
|
||||
var itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0) as Panel;
|
||||
return itemsPanel;
|
||||
}
|
||||
public static T GetVisualChild<T>(DependencyObject parent) where T : Visual
|
||||
{
|
||||
T child = default(T);
|
||||
|
||||
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
|
||||
for (int i = 0; i < numVisuals; i++)
|
||||
{
|
||||
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
|
||||
child = v as T;
|
||||
if (child == null)
|
||||
{
|
||||
child = GetVisualChild<T>(v);
|
||||
}
|
||||
if (child != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return child;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user