alielie
2025-07-04 0940f31b7eba1cf6b6a8c1fca72d97cf686e79f2
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
using System.Windows;
using System.Windows.Controls;
 
namespace WPFProject.Controls
{
    /// <summary>
    /// WinFormHolder.xaml 的交互逻辑
    /// </summary>
    public partial class WinFormHolder : UserControl
    {
 
        private HolderForm holderForm;
        public WinFormHolder()
        {
            holderForm = new HolderForm();
            InitializeComponent();
            holderForm.TopLevel = false;
            holderForm.Dock = System.Windows.Forms.DockStyle.Fill;
            host.Child = holderForm;
        }
 
        public object Content
        {
            get => holderForm?.Content;
            set => holderForm?.UpdateChild(value);
        }
 
        public bool MaskVisiable
        {
            get => GetMaskVisiable(this);
            set => SetMaskVisiable(this, value);
        }
 
        public static bool GetMaskVisiable(WinFormHolder obj)
        {
            return (bool)obj.GetValue(MaskVisiableProperty);
        }
 
        public static void SetMaskVisiable(WinFormHolder obj, bool? value)
        {
            obj.SetValue(MaskVisiableProperty, value);
        }
 
        public static readonly DependencyProperty MaskVisiableProperty =
            DependencyProperty.RegisterAttached("MaskVisiable", typeof(bool?), typeof(WinFormHolder)
                , new PropertyMetadata(null, OnSpaceChanged));
 
        private static void OnSpaceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is WinFormHolder obj)
            {
                if (e.NewValue is bool flag && flag == true)
                {
                    obj.holderForm.ShowMask();
                }
                else
                {
                    obj.holderForm.HideMask();
                }
            }
        }
    }
}