只使用代码方式创建

This commit is contained in:
Bunny 2024-12-30 10:34:15 +08:00
parent 400d5eae63
commit ffa145525a
7 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<Application x:Class="WPF基础_1_1_只使用代码方式创建.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF基础_1_1_只使用代码方式创建"
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基础_1_1_只使用代码方式创建;
/// <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,9 @@
<Window x:Class="WPF基础_1_1_只使用代码方式创建.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="MainWindow" Height="450" Width="800">
<Grid Name="ContainerGrid" />
</Window>

View File

@ -0,0 +1,48 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace WPF基础_1_1_只使用代码方式创建;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Button? _button;
public MainWindow()
{
InitializeComponent();
InitializeComponent1();
}
private void InitializeComponent1()
{
Width = Height = 285;
Left = Top = 100;
Title = "只使用代码创建";
// 创建面板
// var panel = new DockPanel();
var panel = ContainerGrid;
// 创建按钮
_button = new Button();
_button.Content = "点击我";
_button.Margin = new Thickness(30);
_button.Click += Button_OnClick;
// 添加元素
IAddChild container = panel;
container.AddChild(_button);
// container = this;
// container.AddChild(panel);
}
private void Button_OnClick(object sender, RoutedEventArgs eventArgs)
{
_button!.Content = "栓Q";
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>WPF基础_1_1_只使用代码方式创建</RootNamespace>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

View File

@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础", "WPF基础\WPF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1", "WPF基础-1\WPF基础-1.csproj", "{170C5C64-A7D4-4507-B11E-8DB65F1AF1E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1-1-只使用代码方式创建", "WPF基础-1-1-只使用代码方式创建\WPF基础-1-1-只使用代码方式创建.csproj", "{BD355183-DF6F-49EC-A933-0B32280BC5B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -18,5 +20,9 @@ Global
{170C5C64-A7D4-4507-B11E-8DB65F1AF1E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{170C5C64-A7D4-4507-B11E-8DB65F1AF1E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{170C5C64-A7D4-4507-B11E-8DB65F1AF1E6}.Release|Any CPU.Build.0 = Release|Any CPU
{BD355183-DF6F-49EC-A933-0B32280BC5B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD355183-DF6F-49EC-A933-0B32280BC5B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD355183-DF6F-49EC-A933-0B32280BC5B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD355183-DF6F-49EC-A933-0B32280BC5B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal