整理
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<Application
|
||||
StartupUri="MainWindow.xaml"
|
||||
x:Class="NeumUITest.App"
|
||||
x:Class="NeoUITest.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:enu="https://github.com/ShrlAlgo/LucentUI"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -10,10 +10,13 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<!-- <enu:ThemesDictionary Theme="Dark" /> -->
|
||||
<!-- <enu:ControlsDictionary /> -->
|
||||
|
||||
<ResourceDictionary Source="pack://application:,,,/NeoUI;component/Themes/ColorPalette/LightBlue.xaml"/>
|
||||
<ResourceDictionary Source="pack://application:,,,/NeoUI;component/Themes/Light.xaml" />
|
||||
<!--<ResourceDictionary Source="pack://application:,,,/NeuWPF;component/Themes/Dark.xaml" />-->
|
||||
<ResourceDictionary Source="pack://application:,,,/NeoUI;component/Themes/Styles.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/NeumUITest;component/LocalResources.xaml" />
|
||||
<!--<ResourceDictionary Source="pack://application:,,,/NeoUI;component/Themes/ColorPalette/DarkBlue.xaml"/>
|
||||
<ResourceDictionary Source="pack://application:,,,/NeuWPF;component/Themes/Dark.xaml" />-->
|
||||
<!--<ResourceDictionary Source="pack://application:,,,/NeoUITest;component/LocalResources.xaml" />-->
|
||||
|
||||
<!-- <ResourceDictionary Source="pack://application:,,,/LucentUI;component/Themes/Extra.xaml" /> -->
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Windows;
|
||||
|
||||
using NeoUI;
|
||||
|
||||
namespace NeumUITest
|
||||
namespace NeoUITest
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
@@ -18,7 +18,7 @@ namespace NeumUITest
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
//Splash.ShowAsync("pack://application:,,,/NeumUITest;component/Resources/Images/ImageTest.png");
|
||||
//Splash.ShowAsync("pack://application:,,,/NeoUITest;component/Resources/Images/ImageTest.png");
|
||||
//MainWindow = new MainWindow();
|
||||
//Splash.CloseOnLoaded(MainWindow);
|
||||
//MainWindow.Show();
|
||||
|
||||
169
NeuWPF/NeoUITest/ColorPaletteControl.xaml
Normal file
169
NeuWPF/NeoUITest/ColorPaletteControl.xaml
Normal file
@@ -0,0 +1,169 @@
|
||||
<UserControl
|
||||
Height="Auto"
|
||||
Width="Auto"
|
||||
x:Class="NeoUITest.ColorPaletteControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:local="clr-namespace:NeoUITest"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<UserControl.Resources>
|
||||
<DataTemplate x:Key="ColorItemTemplate">
|
||||
<Border
|
||||
Background="{Binding Value}"
|
||||
BorderBrush="#CCC"
|
||||
BorderThickness="1"
|
||||
CornerRadius="8"
|
||||
Margin="4">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Ellipse
|
||||
Fill="{Binding Value}"
|
||||
Height="32"
|
||||
Margin="8,0"
|
||||
Stroke="#888"
|
||||
StrokeThickness="1"
|
||||
Width="32" />
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
FontWeight="SemiBold"
|
||||
Text="{Binding Key}"
|
||||
TextWrapping="WrapWithOverflow" />
|
||||
<TextBlock FontSize="12" Text="{Binding Value}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="BrushItemTemplate">
|
||||
<Border
|
||||
Background="{Binding Value}"
|
||||
BorderBrush="#CCC"
|
||||
BorderThickness="1"
|
||||
CornerRadius="8"
|
||||
Margin="4">
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
|
||||
<Ellipse
|
||||
Fill="{Binding Value}"
|
||||
Height="32"
|
||||
Margin="8,0"
|
||||
Stroke="#888"
|
||||
StrokeThickness="1"
|
||||
Width="32" />
|
||||
<StackPanel>
|
||||
<TextBlock FontWeight="SemiBold" Text="{Binding Key}" />
|
||||
<TextBlock FontSize="12" Text="{Binding Value.Color}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
<!-- 新增颜色分组 -->
|
||||
<CollectionViewSource Source="{Binding ColorResources}" x:Key="ColorGroups">
|
||||
<CollectionViewSource.GroupDescriptions>
|
||||
<PropertyGroupDescription PropertyName="Prefix" />
|
||||
</CollectionViewSource.GroupDescriptions>
|
||||
</CollectionViewSource>
|
||||
<CollectionViewSource Source="{Binding BrushResources}" x:Key="BrushGroups">
|
||||
<CollectionViewSource.GroupDescriptions>
|
||||
<PropertyGroupDescription PropertyName="Prefix" />
|
||||
</CollectionViewSource.GroupDescriptions>
|
||||
</CollectionViewSource>
|
||||
</UserControl.Resources>
|
||||
<StackPanel
|
||||
Background="Transparent"
|
||||
Margin="16"
|
||||
Orientation="Vertical">
|
||||
<StackPanel Visibility="Collapsed">
|
||||
<TextBlock
|
||||
FontSize="14"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,8"
|
||||
Text="颜色资源" />
|
||||
<!-- 用 ListView 支持分组 -->
|
||||
<ListView
|
||||
Height="300"
|
||||
ItemTemplate="{StaticResource ColorItemTemplate}"
|
||||
ItemsSource="{Binding Source={StaticResource ColorGroups}}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Auto"
|
||||
Style="{x:Null}"
|
||||
Visibility="Collapsed">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="IsHitTestVisible" Value="False" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel
|
||||
ItemHeight="60"
|
||||
ItemWidth="320"
|
||||
Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListView.ItemsPanel>
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Margin="0,8,0,4"
|
||||
Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListView.GroupStyle>
|
||||
</ListView>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock
|
||||
FontSize="14"
|
||||
FontWeight="Bold"
|
||||
Margin="16,12,0,8"
|
||||
Text="画刷资源"
|
||||
TextWrapping="WrapWithOverflow" />
|
||||
<ListView
|
||||
Height="300"
|
||||
ItemTemplate="{StaticResource BrushItemTemplate}"
|
||||
ItemsSource="{Binding Source={StaticResource BrushGroups}}"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Visible"
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
Style="{x:Null}">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="IsHitTestVisible" Value="False" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel
|
||||
ItemHeight="60"
|
||||
ItemWidth="320"
|
||||
Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListView.ItemsPanel>
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
FontSize="16"
|
||||
FontWeight="Bold"
|
||||
Margin="0,8,0,4"
|
||||
Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListView.GroupStyle>
|
||||
</ListView>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
87
NeuWPF/NeoUITest/ColorPaletteControl.xaml.cs
Normal file
87
NeuWPF/NeoUITest/ColorPaletteControl.xaml.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace NeoUITest
|
||||
{
|
||||
public partial class ColorPaletteControl : UserControl
|
||||
{
|
||||
public List<ResourceItem> ColorResources { get; set; }
|
||||
public List<ResourceItem> BrushResources { get; set; }
|
||||
|
||||
public static readonly DependencyProperty SourceUriProperty =
|
||||
DependencyProperty.Register("SourceUri", typeof(string), typeof(ColorPaletteControl), new PropertyMetadata(null, OnSourceUriChanged));
|
||||
|
||||
public string SourceUri
|
||||
{
|
||||
get { return (string)GetValue(SourceUriProperty); }
|
||||
set { SetValue(SourceUriProperty, value); }
|
||||
}
|
||||
|
||||
private static void OnSourceUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
ColorPaletteControl control = (ColorPaletteControl)d;
|
||||
string uriString = (string)e.NewValue;
|
||||
|
||||
if (!string.IsNullOrEmpty(uriString))
|
||||
{
|
||||
control.LoadResources(new Uri(uriString, UriKind.RelativeOrAbsolute));
|
||||
}
|
||||
}
|
||||
private void LoadResources(Uri uri)
|
||||
{
|
||||
var resourceDictionary = new ResourceDictionary
|
||||
{
|
||||
Source = uri
|
||||
};
|
||||
|
||||
ColorResources.Clear();
|
||||
BrushResources.Clear();
|
||||
|
||||
foreach (DictionaryEntry entry in resourceDictionary)
|
||||
{
|
||||
string key = entry.Key.ToString();
|
||||
// 用正则分割驼峰或 Pascal 命名,取第一个单词
|
||||
var match = Regex.Match(key, @"^[A-Z][a-z]*");
|
||||
string prefix = match.Success ? match.Value : key;
|
||||
if (entry.Value is Color color)
|
||||
{
|
||||
ColorResources.Add(new ResourceItem { Key = entry.Key.ToString(), Prefix = prefix, Value = new SolidColorBrush(color) });
|
||||
}
|
||||
else if (entry.Value is SolidColorBrush brush)
|
||||
{
|
||||
BrushResources.Add(new ResourceItem { Key = key, Value = brush, Prefix = prefix });
|
||||
}
|
||||
}
|
||||
ColorResources = ColorResources.OrderBy(c => c.Key).ToList();
|
||||
BrushResources = BrushResources.OrderBy(c => c.Key).ToList();
|
||||
DataContext = this;
|
||||
}
|
||||
public ColorPaletteControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
ColorResources = new List<ResourceItem>();
|
||||
BrushResources = new List<ResourceItem>();
|
||||
}
|
||||
|
||||
public IEnumerable<IGrouping<string, ResourceItem>> GroupedBrushResources
|
||||
{
|
||||
get
|
||||
{
|
||||
return BrushResources.GroupBy(b => b.Prefix);
|
||||
}
|
||||
}
|
||||
|
||||
public class ResourceItem
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public SolidColorBrush Value { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
17
NeuWPF/NeoUITest/ColorPaletteWindow.xaml
Normal file
17
NeuWPF/NeoUITest/ColorPaletteWindow.xaml
Normal file
@@ -0,0 +1,17 @@
|
||||
<n:NeoWindow
|
||||
Height="450"
|
||||
Icon="/Resources/Images/ImageTest.png"
|
||||
Title="ColorPaletteWindow"
|
||||
Width="800"
|
||||
mc:Ignorable="d"
|
||||
x:Class="NeoUITest.ColorPaletteWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:NeoUITest"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:n="https://github.com/ShrlAlgo/NeoUI"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Grid>
|
||||
<local:ColorPaletteControl SourceUri="pack://application:,,,/NeoUI;component/Themes/Light.xaml" />
|
||||
</Grid>
|
||||
</n:NeoWindow>
|
||||
28
NeuWPF/NeoUITest/ColorPaletteWindow.xaml.cs
Normal file
28
NeuWPF/NeoUITest/ColorPaletteWindow.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace NeoUITest
|
||||
{
|
||||
/// <summary>
|
||||
/// ColorPaletteWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ColorPaletteWindow
|
||||
{
|
||||
public ColorPaletteWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@
|
||||
d:Height="1200"
|
||||
d:SizeToContent="WidthAndHeight"
|
||||
mc:Ignorable="d"
|
||||
x:Class="LumeTest.ControlTestWindow"
|
||||
x:Class="NeoUITest.ControlTestWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:neu="https://github.com/ShrlAlgo/NeuWPF"
|
||||
xmlns:neu="https://github.com/ShrlAlgo/NeoUI"
|
||||
xmlns:sys="clr-namespace:System;assembly=netfx.force.conflicts"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<!-- 主窗口背景色,这是拟态风格的基础 -->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
|
||||
namespace NeumUITest
|
||||
namespace NeoUITest
|
||||
{
|
||||
/// <summary>
|
||||
/// ControlTestWindow.xaml 的交互逻辑
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace NeumUITest.DataModel
|
||||
namespace NeoUITest.DataModel
|
||||
{
|
||||
public enum Gender
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NeumUITest.DataModel
|
||||
namespace NeoUITest.DataModel
|
||||
{
|
||||
public class TreeItemData
|
||||
{
|
||||
|
||||
131
NeuWPF/NeoUITest/IconsWindow.xaml
Normal file
131
NeuWPF/NeoUITest/IconsWindow.xaml
Normal file
@@ -0,0 +1,131 @@
|
||||
<n:NeoWindow
|
||||
Height="450"
|
||||
Title="IconsWindow"
|
||||
Width="820"
|
||||
d:DataContext="{d:DesignInstance Type=local:IconsWindow}"
|
||||
mc:Ignorable="d"
|
||||
x:Class="NeoUITest.IconsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:NeoUITest"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:n="https://github.com/ShrlAlgo/NeoUI"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 第一行: 搜索框 -->
|
||||
<Border
|
||||
BorderBrush="LightGray"
|
||||
BorderThickness="0,0,0,1"
|
||||
Grid.Row="0"
|
||||
Padding="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox
|
||||
FontSize="14"
|
||||
Grid.Column="1"
|
||||
Padding="5"
|
||||
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
|
||||
VerticalContentAlignment="Center">
|
||||
<n:InputAssist.Suffix>
|
||||
<n:IconElement
|
||||
FontSize="18"
|
||||
Foreground="Gray"
|
||||
Margin="0,0,10,0"
|
||||
Symbol="Search"
|
||||
VerticalAlignment="Center" />
|
||||
</n:InputAssist.Suffix>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 第二行: 选中图标信息和复制代码 -->
|
||||
<Border
|
||||
BorderBrush="LightGray"
|
||||
BorderThickness="0,0,0,1"
|
||||
Grid.Row="1"
|
||||
Padding="10">
|
||||
<n:FlexibleRowPanel LayoutMode="Auto">
|
||||
<TextBlock
|
||||
FontWeight="Bold"
|
||||
Text="选中图标:"
|
||||
VerticalAlignment="Center" />
|
||||
<!-- 确保绑定是 OneWay,因为我们只从后台更新UI -->
|
||||
<TextBox
|
||||
FontWeight="Bold"
|
||||
Foreground="DodgerBlue"
|
||||
IsReadOnly="True"
|
||||
Margin="10,0"
|
||||
Padding="5"
|
||||
Text="{Binding SelectedSymbolName, Mode=OneWay, FallbackValue='请选择一个图标...'}"
|
||||
VerticalAlignment="Center"
|
||||
n:FlexibleRowPanel.IsFill="True" />
|
||||
<Button
|
||||
Click="CopyCode_Click"
|
||||
Content="复制代码"
|
||||
Padding="10,5"
|
||||
VerticalAlignment="Center" />
|
||||
<n:ColorPicker
|
||||
Margin="10,0,0,0"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="ColorPicker" />
|
||||
</n:FlexibleRowPanel>
|
||||
</Border>
|
||||
|
||||
<!-- 第三行: 图标浏览器 -->
|
||||
<ListBox
|
||||
Grid.Row="2"
|
||||
ItemsSource="{Binding SymbolCollectionView}"
|
||||
Name="IconItemsControl"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
SelectionChanged="IconItemsControl_SelectionChanged">
|
||||
<ListBox.Foreground>
|
||||
<SolidColorBrush Color="{Binding ElementName=ColorPicker, Path=SelectedColor}" />
|
||||
</ListBox.Foreground>
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel ItemHeight="80" ItemWidth="80" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel HorizontalAlignment="Center">
|
||||
<n:IconElement
|
||||
FontSize="32"
|
||||
Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=Foreground}"
|
||||
Symbol="{Binding}"
|
||||
ToolTip="{Binding}" />
|
||||
<TextBlock
|
||||
FontSize="12"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,5,0,0"
|
||||
Text="{Binding}"
|
||||
TextWrapping="Wrap"
|
||||
ToolTip="{Binding}"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
<!--<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#CCE8FF" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>-->
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</n:NeoWindow>
|
||||
139
NeuWPF/NeoUITest/IconsWindow.xaml.cs
Normal file
139
NeuWPF/NeoUITest/IconsWindow.xaml.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
using NeoUI.Assets;
|
||||
|
||||
namespace NeoUITest;
|
||||
/// <summary>
|
||||
/// IconsWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class IconsWindow : INotifyPropertyChanged
|
||||
{
|
||||
// 1. 一个私有的、包含所有图标的原始数据集合
|
||||
private readonly ObservableCollection<MaterialSymbol> _allSymbols = new ObservableCollection<MaterialSymbol>();
|
||||
|
||||
// 2. 一个公开的 ICollectionView,UI 将绑定到这个视图
|
||||
public ICollectionView SymbolCollectionView { get; }
|
||||
|
||||
private string _selectedSymbolName;
|
||||
public string SelectedSymbolName
|
||||
{
|
||||
get => _selectedSymbolName;
|
||||
set { _selectedSymbolName = value; OnPropertyChanged(nameof(SelectedSymbolName)); }
|
||||
}
|
||||
|
||||
private string _searchText = string.Empty;
|
||||
// 3. 绑定到搜索框的属性
|
||||
public string SearchText
|
||||
{
|
||||
get => _searchText;
|
||||
set
|
||||
{
|
||||
if (_searchText == value) return;
|
||||
_searchText = value;
|
||||
OnPropertyChanged(nameof(SearchText));
|
||||
|
||||
// 关键点: 当搜索文本改变时,刷新视图以重新应用筛选
|
||||
SymbolCollectionView.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public IconsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// 从枚举加载所有图标到原始集合
|
||||
LoadSymbols();
|
||||
|
||||
// 4. 初始化视图
|
||||
SymbolCollectionView = CollectionViewSource.GetDefaultView(_allSymbols);
|
||||
|
||||
// 5. 为视图指定筛选逻辑
|
||||
SymbolCollectionView.Filter = FilterSymbols;
|
||||
|
||||
this.DataContext = this;
|
||||
}
|
||||
|
||||
private void LoadSymbols()
|
||||
{
|
||||
var symbols = Enum.GetValues(typeof(MaterialSymbol)).Cast<MaterialSymbol>();
|
||||
_allSymbols.Clear();
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
_allSymbols.Add(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 筛选方法的具体实现
|
||||
private bool FilterSymbols(object item)
|
||||
{
|
||||
// 如果搜索框为空,则不过滤,显示所有项
|
||||
if (string.IsNullOrEmpty(SearchText))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果项是 MaterialSymbol 类型
|
||||
if (item is MaterialSymbol symbol)
|
||||
{
|
||||
// 检查枚举的名称(不区分大小写)是否包含搜索文本
|
||||
return symbol.ToString().IndexOf(SearchText, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// *** 选择修复: 直接从事件参数 e 中获取选中的项 ***
|
||||
private void IconItemsControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
// 检查 e.AddedItems 是否有内容。AddedItems 包含了新选中的项。
|
||||
if (e.AddedItems.Count > 0 && e.AddedItems[0] is MaterialSymbol selectedSymbol)
|
||||
{
|
||||
string xamlCode = $"<n:IconElement Symbol=\"{selectedSymbol}\" Foreground=\"{ColorPicker.SelectedColor}\"/>";
|
||||
SelectedSymbolName = xamlCode;
|
||||
|
||||
}
|
||||
// 如果列表被清空或选择被取消,e.AddedItems 为空
|
||||
else if (IconItemsControl.SelectedItem == null)
|
||||
{
|
||||
SelectedSymbolName = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyCode_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(SelectedSymbolName))
|
||||
{
|
||||
//string xamlCode = $"<local:SymbolIcon Symbol=\"{SelectedSymbolName}\" />";
|
||||
|
||||
Clipboard.SetText(SelectedSymbolName);
|
||||
//MessageBox.Show($"代码已复制到剪贴板!\n\n{SelectedSymbolName}", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先选择一个图标。", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
protected void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -12,7 +14,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using NeoUI.Appearance;
|
||||
using NeoUI.Controls;
|
||||
|
||||
namespace NeumUITest;
|
||||
namespace NeoUITest;
|
||||
|
||||
/// <summary>
|
||||
/// MainWindow.xaml 的交互逻辑
|
||||
@@ -302,14 +304,31 @@ public partial class MainWindow
|
||||
|
||||
}
|
||||
|
||||
private void DarkTheme(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ThemeManager.SetThemeMode(ThemeMode.Dark);
|
||||
}
|
||||
// 重入保护标志
|
||||
private bool _themeAnimating;
|
||||
|
||||
private void LightTheme(object sender, RoutedEventArgs e)
|
||||
// ToggleButton.Checked / Unchecked 都指向这个
|
||||
private async void ThemeToggle_OnCheckedChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ThemeManager.SetThemeMode(ThemeMode.Light);
|
||||
if (_themeAnimating) return; // 丢弃重入,也可以排队
|
||||
if (sender is not ToggleButton tb) return;
|
||||
|
||||
var targetMode = tb.IsChecked == true ? ThemeMode.Dark : ThemeMode.Light;
|
||||
|
||||
try
|
||||
{
|
||||
_themeAnimating = true;
|
||||
// 动画时长可调;若需要与调色板同步也可传 palette
|
||||
await ThemeManager.ApplyThemeAsync(targetMode, null, animate: true, animationDurationMs: 300);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[ThemeToggle] " + ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_themeAnimating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorPalette_OnClick(object sender, RoutedEventArgs e)
|
||||
@@ -321,6 +340,28 @@ public partial class MainWindow
|
||||
};
|
||||
palette.ShowDialog();
|
||||
}
|
||||
|
||||
private void PrimaryColorSelectComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ComboBox box)
|
||||
{
|
||||
switch (box.SelectedIndex)
|
||||
{
|
||||
case 0:
|
||||
ThemeManager.ApplyThemePalette(ThemePalette.Blue);
|
||||
break;
|
||||
case 1:
|
||||
ThemeManager.ApplyThemePalette(ThemePalette.Green);
|
||||
break;
|
||||
case 2:
|
||||
ThemeManager.ApplyThemePalette(ThemePalette.Purple);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class ViewModelBase : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NeumUITest
|
||||
namespace NeoUITest
|
||||
{
|
||||
public class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user