1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
// ref à ajouter
using System.Windows.Controls.Primitives;
namespace WpfResizingGripCanvasCSharp
{
/// <summary>
/// Logique d'interaction pour UserControl3.xaml
/// </summary>
public partial class UserControl3 : UserControl
{
public UserControl3()
{
InitializeComponent();
Children = this.PART_Grid.Children;
}
// prop children permet d'ajouter autant de controls "childs" qu'on veut
// au grid lorsque l'UserControl est droppe sur le form.....
// utilise ici pour pouvoir ajouter un "child" canvas.....
public UIElementCollection Children
{
get { return (UIElementCollection)GetValue(ChildrenProperty); }
set { SetValue(ChildrenProperty, value); }
}
// Using a DependencyProperty as the backing store for Children. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChildrenProperty =
DependencyProperty.Register("Children",
typeof(UIElementCollection),
typeof(UserControl3),
new UIPropertyMetadata(null));
// handler des thumbs
private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
Thumb myThumb=(Thumb)sender;
if (myThumb == null) return;
foreach (UIElement itemUI in this.PART_Grid.Children )
{
if (itemUI is Thumb )
{
Thumb thb = (Thumb)itemUI;
var str1 = (string)thb.Tag;
if (str1.Equals("T") || str1.Equals("L") || str1.Equals("B")
|| str1.Equals("R"))
{
itemUI.Opacity = 1.0;
}
}
}
var str = (string)myThumb.Tag;
if (str.Contains("T"))
{
PART_Grid.Height = Math.Min(Math.Max(PART_Grid.MinHeight, PART_Grid.ActualHeight - e.VerticalChange), PART_Grid.MaxHeight);
Canvas.SetTop(PART_Grid, Canvas.GetTop(PART_Grid) - PART_Grid.Height + PART_Grid.ActualHeight);
}
if (str.Contains("L"))
{
PART_Grid.Width = Math.Min(Math.Max(PART_Grid.MinWidth, PART_Grid.ActualWidth - e.HorizontalChange), PART_Grid.MaxWidth);
Canvas.SetLeft(PART_Grid, Canvas.GetLeft(PART_Grid) - PART_Grid.Width + PART_Grid.ActualWidth);
}
if (str.Contains("B"))
{
PART_Grid.Height = Math.Min(Math.Max(PART_Grid.MinHeight, PART_Grid.ActualHeight + e.VerticalChange), PART_Grid.MaxHeight);
}
if (str.Contains("R"))
{
PART_Grid.Width = Math.Min(Math.Max(PART_Grid.MinWidth, PART_Grid.ActualWidth + e.HorizontalChange), PART_Grid.MaxWidth);
}
e.Handled = true;
}
private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
{
Thumb myThumb = (Thumb)sender;
if (myThumb == null) return;
foreach (UIElement itemUI in this.PART_Grid.Children )
{
if (itemUI is Thumb )
{
Thumb thb = (Thumb)itemUI;
var str1 = (string)thb.Tag;
if (str1.Equals("T") || str1.Equals("L") || str1.Equals("B")|| str1.Equals("R"))
{
thb.Opacity = 0.0;
}
}
}
}
}
} |
Partager