feat: WPF控件-1-设置颜色

This commit is contained in:
Bunny 2025-01-02 20:41:13 +08:00
commit 58ca99a706
8 changed files with 157 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
logs/
application-prod.yml
[b|B]in
[o|O]bj
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF控件.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF控件"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace WPF控件;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,36 @@
<Window x:Class="WPF控件.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="WPF控件" Height="450" Width="800">
<StackPanel>
<WrapPanel>
<Button Name="Cmd" Padding="15 5">Cmd</Button>
<Button Name="TestButton" Padding="15 5">
<Button.Background>
<SolidColorBrush Color="Red" />
</Button.Background>
测试按钮
</Button>
<Button Padding="15 5" Background="#ff00ff">测四按钮</Button>
<Button Name="TestButton2" Padding="15 5" FontFamily="Times New Roman" FontSize="18">一个按钮</Button>
<Button FontFamily="Times New Roman Bold">一个按钮</Button>
<TextBlock TextDecorations="Underline">下划线。。。。</TextBlock>
</WrapPanel>
<TextBlock FontSize="12" TextOptions.TextFormattingMode="Display">
TextOptions.TextFormattingMode="Display"用于显示尺寸小显示模糊的问题
</TextBlock>
<ListBox Name="ListBox" Height="300" />
</StackPanel>
</Window>

View File

@ -0,0 +1,24 @@
using System.Windows;
using System.Windows.Media;
namespace WPF控件;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Cmd.Background = new SolidColorBrush(SystemColors.ControlColor);
// 简写形式
Cmd.Background = SystemColors.ControlBrush;
// 设置字体颜色
Cmd.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
foreach (var fontFamily in Fonts.SystemFontFamilies) ListBox.Items.Add(fontFamily.Source);
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<RootNamespace>WPF控件</RootNamespace>
</PropertyGroup>
</Project>

16
WPF控件.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF控件-1-设置颜色", "WPF控件-1-设置颜色\WPF控件-1-设置颜色.csproj", "{5D1AD019-4A90-48E2-815A-35EE2B002BD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5D1AD019-4A90-48E2-815A-35EE2B002BD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D1AD019-4A90-48E2-815A-35EE2B002BD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D1AD019-4A90-48E2-815A-35EE2B002BD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D1AD019-4A90-48E2-815A-35EE2B002BD2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal