mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.ComponentModel;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class DesignerHelper
|
|
{
|
|
private static bool? _isInDesignMode;
|
|
|
|
public static bool IsInDesignMode
|
|
{
|
|
get
|
|
{
|
|
if (!_isInDesignMode.HasValue)
|
|
{
|
|
_isInDesignMode = (bool)DependencyPropertyDescriptor.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement)).Metadata.DefaultValue;
|
|
}
|
|
return _isInDesignMode.Value;
|
|
}
|
|
}
|
|
|
|
#region IsInMainThread
|
|
|
|
/// <summary>
|
|
/// 是否是在主线程中处理
|
|
/// </summary>
|
|
public static bool IsInMainThread
|
|
{
|
|
get
|
|
{
|
|
if (Thread.CurrentThread.IsBackground || Thread.CurrentThread.IsThreadPoolThread) return false;
|
|
|
|
if (Thread.CurrentThread.Name == "主线程") return true;
|
|
|
|
if (Application.Current == null)
|
|
return true;
|
|
|
|
return Thread.CurrentThread == Application.Current.Dispatcher.Thread;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |