This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -1,6 +1,7 @@
using System.Reflection;
using System.Windows.Markup;
namespace WPFluent.Markup;
@@ -9,7 +10,7 @@ namespace WPFluent.Markup;
/// 提供一个字典实现,其中包含 WPF 应用程序的组件和其他元素使用的 <c>WPF UI</c> 控件资源。
/// </summary>
/// <example>
/// <code lang="xml"> /// &lt;Application /// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"&gt; ///
/// <code lang="xml">/// &lt;Application /// xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"&gt; ///
/// &lt;Application.Resources&gt; /// &lt;ResourceDictionary&gt; ///
/// &lt;ResourceDictionary.MergedDictionaries&gt; /// &lt;ui:ControlsDictionary /&gt; ///
/// &lt;/ResourceDictionary.MergedDictionaries&gt; /// &lt;/ResourceDictionary&gt; ///
@@ -20,11 +21,7 @@ namespace WPFluent.Markup;
[UsableDuringInitialization(true)]
public class ControlsDictionary : ResourceDictionary
{
private const string DictionaryUri = "pack://application:,,,/WPFluent;component/Resources/Styles.xaml";
private string DictionaryUri => $"pack://application:,,,/{Assembly.GetExecutingAssembly().GetName().Name};component/Resources/Styles.xaml";
/// <summary>
/// Initializes a new instance of the <see cref="ControlsDictionary"/> class. Default constructor defining <see
/// cref="ResourceDictionary.Source"/> of the <c>WPF UI</c> controls dictionary.
/// </summary>
public ControlsDictionary() { Source = new Uri(DictionaryUri, UriKind.Absolute); }
}

99
WPFluent/Markup/Design.cs Normal file
View File

@@ -0,0 +1,99 @@
using System.ComponentModel;
using System.Windows;
namespace WPFluent.Markup;
public static class Design
{
private static readonly string[] DesignProcesses =
[
"devenv",
"dotnet",
"RiderWpfPreviewerLauncher64"
];
private static bool? _inDesignMode;
/// <summary>
/// Gets a value indicating whether the framework is in design-time mode. (Caliburn.Micro implementation)
/// </summary>
private static bool InDesignMode =>
_inDesignMode ??=
(bool)
DependencyPropertyDescriptor
.FromProperty(DesignerProperties.IsInDesignModeProperty, typeof(FrameworkElement))
.Metadata.DefaultValue
|| DesignProcesses.Any(process => System
.Diagnostics.Process.GetCurrentProcess()
.ProcessName.StartsWith(process, StringComparison.Ordinal));
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.RegisterAttached(
"Background",
typeof(Brush),
typeof(Design),
new PropertyMetadata(OnBackgroundChanged)
);
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.RegisterAttached(
"Foreground",
typeof(Brush),
typeof(Design),
new PropertyMetadata(OnForegroundChanged)
);
/// <summary>Helper for getting <see cref="BackgroundProperty"/> from <paramref name="dependencyObject"/>.</summary>
/// <param name="dependencyObject"><see cref="DependencyObject"/> to read <see cref="BackgroundProperty"/> from.</param>
/// <returns>Background property value.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"WpfAnalyzers.DependencyProperty",
"WPF0033:Add [AttachedPropertyBrowsableForType]",
Justification = "Because"
)]
public static Brush? GetBackground(DependencyObject dependencyObject) =>
(Brush)dependencyObject.GetValue(BackgroundProperty);
/// <summary>Helper for setting <see cref="BackgroundProperty"/> on <paramref name="dependencyObject"/>.</summary>
/// <param name="dependencyObject"><see cref="DependencyObject"/> to set <see cref="BackgroundProperty"/> on.</param>
/// <param name="value">Background property value.</param>
public static void SetBackground(DependencyObject dependencyObject, Brush? value) =>
dependencyObject.SetValue(BackgroundProperty, value);
/// <summary>Helper for getting <see cref="ForegroundProperty"/> from <paramref name="dependencyObject"/>.</summary>
/// <param name="dependencyObject"><see cref="DependencyObject"/> to read <see cref="ForegroundProperty"/> from.</param>
/// <returns>Foreground property value.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"WpfAnalyzers.DependencyProperty",
"WPF0033:Add [AttachedPropertyBrowsableForType]",
Justification = "Because"
)]
public static Brush? GetForeground(DependencyObject dependencyObject) =>
(Brush)dependencyObject.GetValue(ForegroundProperty);
/// <summary>Helper for setting <see cref="ForegroundProperty"/> on <paramref name="dependencyObject"/>.</summary>
/// <param name="dependencyObject"><see cref="DependencyObject"/> to set <see cref="ForegroundProperty"/> on.</param>
/// <param name="value">Foreground property value.</param>
public static void SetForeground(DependencyObject dependencyObject, Brush? value) =>
dependencyObject.SetValue(ForegroundProperty, value);
private static void OnBackgroundChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e)
{
if (!InDesignMode)
{
return;
}
d?.GetType()?.GetProperty("Background")?.SetValue(d, e.NewValue, null);
}
private static void OnForegroundChanged(DependencyObject? d, DependencyPropertyChangedEventArgs e)
{
if (!InDesignMode)
{
return;
}
d?.GetType()?.GetProperty("Foreground")?.SetValue(d, e.NewValue, null);
}
}

View File

@@ -1,9 +1,11 @@
using WPFluent.Controls;
using System.Windows.Markup;
using System.Windows.Media.Imaging;
using WPFluent.Controls;
namespace WPFluent.Markup;
@@ -22,7 +24,10 @@ namespace WPFluent.Markup;
public class ImageIconExtension : MarkupExtension
{
public ImageIconExtension(ImageSource? source) { Source = source; }
public ImageIconExtension(string source)
{
Source = new BitmapImage(new Uri(source, UriKind.RelativeOrAbsolute));
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
var imageIcon = new ImageIcon { Source = Source, Width = Width, Height = Height, };

View File

@@ -1,10 +1,11 @@
using WPFluent.Controls;
using System.Windows.Markup;
using WPFluent.Controls;
namespace WPFluent.Markup;
/// <summary>