| | |
| | | using System; |
| | | using HandyControl.Controls; |
| | | using System; |
| | | using System.ComponentModel; |
| | | using System.Runtime.CompilerServices; |
| | | using System.Windows; |
| | |
| | | /// InnerWindow.xaml 的交互逻辑 |
| | | /// </summary> |
| | | public partial class InnerWindow : UserControl, INotifyPropertyChanged |
| | | { |
| | | {
|
| | | #region INotifyPropertyChanged |
| | | public virtual event PropertyChangedEventHandler PropertyChanged; |
| | | |
| | | protected virtual void RaisePropertyChanged(string name) |
| | |
| | | { |
| | | RaisePropertyChanged(propertyName); |
| | | } |
| | | } |
| | | |
| | | public CanvasPosition canvasPosition; |
| | | |
| | | }
|
| | | #endregion |
| | |
|
| | | #region 属性 |
| | |
|
| | | #region Common |
| | | public DragType DragType { get; set; } = DragType.Canvas; |
| | | |
| | | public CanvasPosition canvasPosition; |
| | | private Canvas canvas; |
| | | public WindowState WindowState { get; set; } = WindowState.Normal; |
| | | public AdornerDecorator ResizeAdornerDecorator { get => VisualTreeHelper.GetChild(this, 0) as AdornerDecorator; }
|
| | |
|
| | | private string _Title; |
| | | public string Title |
| | | { |
| | | get { return _Title; } |
| | | set => RaiseAndSetIfChanged(ref _Title, value); |
| | | }
|
| | |
|
| | | public int Zindex |
| | | { |
| | | get { |
| | | get
|
| | | { |
| | | return Canvas.GetZIndex(this); |
| | | } |
| | | set |
| | | { |
| | | Canvas.SetZIndex(this, value); |
| | | } |
| | | } |
| | | |
| | | public AdornerDecorator ResizeAdornerDecorator { get => VisualTreeHelper.GetChild(this, 0) as AdornerDecorator; } |
| | | |
| | | |
| | | }
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region 事件 |
| | | public event EventHandler MinEvent; |
| | | public event EventHandler MaxEvent; |
| | | public event EventHandler CloseEvent; |
| | | public event EventHandler ZIndexEvent; |
| | | |
| | | public WindowState WindowState { get; set; } = WindowState.Normal; |
| | | |
| | | private string _Title; |
| | | |
| | | public string Title |
| | | { |
| | | get { return _Title; } |
| | | set => RaiseAndSetIfChanged(ref _Title, value); |
| | | } |
| | | |
| | | public event EventHandler ZIndexEvent;
|
| | | #endregion
|
| | |
|
| | | #region DependencyProperty |
| | | public Brush HeaderBackground |
| | | { |
| | | get { return (Brush)GetValue(HeaderBackgroundProperty); } |
| | |
| | | |
| | | public static readonly DependencyProperty HeaderFontColorProperty = |
| | | DependencyProperty.Register("HeaderFontColor", typeof(Brush), typeof(ProgramList), |
| | | new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 255, 225)))); |
| | | |
| | | new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 255, 225))));
|
| | | #endregion
|
| | |
|
| | | #endregion
|
| | |
|
| | | public InnerWindow() : this(null) |
| | | { |
| | | |
| | |
| | | |
| | | DataContext = this; |
| | | InitializeComponent(); |
| | | SizeChanged += InnerWindow_SizeChanged; |
| | | Loaded += InnerWindow_Loaded; |
| | | } |
| | | |
| | | private void InnerWindow_SizeChanged(object sender, SizeChangedEventArgs e) |
| | | { |
| | | //throw new NotImplementedException(); |
| | | } |
| | | |
| | | private void InitThumb() |
| | | { |
| | | |
| | | } |
| | | |
| | | // 方形工厂 |
| | | FrameworkElementFactory GetFactory(Brush back) |
| | | { |
| | | FrameworkElementFactory fac = new FrameworkElementFactory(typeof(Rectangle)); |
| | | fac.SetValue(Rectangle.FillProperty, back); |
| | | return fac; |
| | | } |
| | | |
| | | private void InnerWindow_Loaded(object sender, RoutedEventArgs e) |
| | |
| | | }; |
| | | } |
| | | Loaded -= InnerWindow_Loaded; |
| | | } |
| | | |
| | | private Canvas canvas; |
| | | |
| | | private void Button_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | Visibility = Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible; |
| | | } |
| | | |
| | | }
|
| | |
|
| | | #region 拖拽移动相关 |
| | | private void DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e) |
| | | { |
| | | switch (DragType) |
| | |
| | | { |
| | | canvasPosition.Top = Canvas.GetTop(this); |
| | | canvasPosition.Left = Canvas.GetLeft(this); |
| | | } |
| | | |
| | | private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) |
| | | { |
| | | |
| | | } |
| | | }
|
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 添加到画布上 |
| | |
| | | } |
| | | Canvas.SetLeft(this, canvasPosition == null ? 0 : canvasPosition.Left); |
| | | Canvas.SetTop(this, canvasPosition == null ? 0 : canvasPosition.Top); |
| | | } |
| | | |
| | | canvas.SizeChanged += Canvas_SizeChanged; |
| | | }
|
| | |
|
| | | private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
|
| | | {
|
| | | Size newSize = e.NewSize;
|
| | | Size previousSize = e.PreviousSize;
|
| | |
|
| | | double xRate = newSize.Width / previousSize.Width;
|
| | | double yRate = newSize.Height / previousSize.Height;
|
| | |
|
| | | Canvas.SetLeft(this, Canvas.GetLeft(this) * xRate);
|
| | | Canvas.SetTop(this, Canvas.GetTop(this) * yRate);
|
| | | this.Width = this.Width * xRate;
|
| | | this.Height = this.Height * yRate;
|
| | | }
|
| | |
|
| | | private void Min_Click(object sender, RoutedEventArgs e) |
| | | { |
| | | MinEvent?.Invoke(this, null); |
| | |
| | | {
|
| | |
|
| | | }
|
| | | } |
| | | |
| | | public class InnerWindowProp : NotifyBase |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | public enum DragType |