92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
namespace _29WxOrderWpf.Common
|
|
{
|
|
/// <summary>
|
|
/// DialogWindow.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class DialogWindow : Window
|
|
{
|
|
private readonly Style dialogWindowStyle;
|
|
private bool isConstructorSuccessful = false;
|
|
public DialogWindow()
|
|
{
|
|
InitializeComponent();
|
|
Owner = Application.Current.MainWindow;
|
|
isConstructorSuccessful = true;
|
|
dialogWindowStyle = (Style)TryFindResource("DialogWindowStyle");
|
|
|
|
Loaded += DialogWindow_Loaded;
|
|
}
|
|
private void DialogWindow_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
Loaded -= DialogWindow_Loaded;
|
|
|
|
}
|
|
protected override void OnContentChanged(object oldContent, object newContent)
|
|
{
|
|
this.Style = dialogWindowStyle;
|
|
if (newContent is System.Windows.Controls.UserControl control)
|
|
{
|
|
|
|
Setter widthSetter = this.Style.Setters.OfType<Setter>().FirstOrDefault(a => a.Property == WidthProperty);
|
|
if (widthSetter == null)
|
|
{
|
|
if (double.IsNaN(control.Width))
|
|
{
|
|
this.Width = DialogWindowProperty.GetWidth(control);
|
|
}
|
|
else
|
|
{
|
|
this.Width = control.Width;
|
|
control.Width = double.NaN;
|
|
}
|
|
}
|
|
|
|
|
|
Setter heightSetter = this.Style.Setters.OfType<Setter>().FirstOrDefault(a => a.Property == HeightProperty);
|
|
if (heightSetter == null)
|
|
{
|
|
if (double.IsNaN(control.Height))
|
|
{
|
|
this.Height = DialogWindowProperty.GetHeight(control);
|
|
}
|
|
else
|
|
{
|
|
this.Height = control.Height;
|
|
control.Height = double.NaN;
|
|
}
|
|
}
|
|
|
|
|
|
ResizeMode resizeExt = DialogWindowProperty.GetResizeMode(control);
|
|
if (resizeExt != ResizeMode.CanResize)
|
|
{
|
|
this.ResizeMode = resizeExt;
|
|
}
|
|
|
|
}
|
|
base.OnContentChanged(oldContent, newContent);
|
|
}
|
|
|
|
protected override void OnStyleChanged(Style oldStyle, Style newStyle)
|
|
{
|
|
if (newStyle.TargetType == typeof(Window))
|
|
{
|
|
if (isConstructorSuccessful)
|
|
{
|
|
//dialogWindowStyle.Merge(newStyle);
|
|
}
|
|
return;
|
|
}
|
|
base.OnStyleChanged(oldStyle, newStyle);
|
|
}
|
|
}
|
|
}
|