|
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace CBR.Components.Designer
{
public class DesignerItem : ContentControl
{
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
public static readonly DependencyProperty IsSelectedProperty =
DependencyProperty.Register("IsSelected", typeof(bool),
typeof(DesignerItem),
new FrameworkPropertyMetadata(false));
public static readonly DependencyProperty MoveThumbTemplateProperty =
DependencyProperty.RegisterAttached("MoveThumbTemplate", typeof(ControlTemplate), typeof(DesignerItem));
public static ControlTemplate GetMoveThumbTemplate(UIElement element)
{
return (ControlTemplate)element.GetValue(MoveThumbTemplateProperty);
}
public static void SetMoveThumbTemplate(UIElement element, ControlTemplate value)
{
element.SetValue(MoveThumbTemplateProperty, value);
}
static DesignerItem()
{
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(DesignerItem), new FrameworkPropertyMetadata(typeof(DesignerItem)));
}
public DesignerItem()
{
//this.Loaded += new RoutedEventHandler(this.DesignerItem_Loaded);
}
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseDown(e);
DesignerCanvas designer = VisualTreeHelper.GetParent(this) as DesignerCanvas;
if (designer != null)
{
if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
{
this.IsSelected = !this.IsSelected;
}
else
{
if (!this.IsSelected)
{
designer.DeselectAll();
this.IsSelected = true;
}
}
}
e.Handled = false;
}
//private void DesignerItem_Loaded(object sender, RoutedEventArgs e)
//{
// if (this.Template != null)
// {
// ContentPresenter contentPresenter =
// this.Template.FindName("PART_ContentPresenter", this) as ContentPresenter;
// MoveThumb thumb =
// this.Template.FindName("PART_MoveThumb", this) as MoveThumb;
// //if (contentPresenter != null && thumb != null)
// //{
// // UIElement contentVisual =
// // VisualTreeHelper.GetChild(contentPresenter, 0) as UIElement;
// // if (contentVisual != null)
// // {
// // ControlTemplate template =
// // DesignerItem.GetMoveThumbTemplate(contentVisual) as ControlTemplate;
// // if (template != null)
// // {
// // thumb.Template = template;
// // }
// // }
// //}
// }
//}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/