diff --git a/WPF基础-1-1-只使用代码方式创建/App.xaml b/WPF基础-1-1-只使用代码方式创建/App.xaml new file mode 100644 index 0000000..ab14a55 --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WPF基础-1-1-只使用代码方式创建/App.xaml.cs b/WPF基础-1-1-只使用代码方式创建/App.xaml.cs new file mode 100644 index 0000000..61a3bf5 --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WPF基础_1_1_只使用代码方式创建; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} \ No newline at end of file diff --git a/WPF基础-1-1-只使用代码方式创建/AssemblyInfo.cs b/WPF基础-1-1-只使用代码方式创建/AssemblyInfo.cs new file mode 100644 index 0000000..4a05c7d --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/AssemblyInfo.cs @@ -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) +)] \ No newline at end of file diff --git a/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml b/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml new file mode 100644 index 0000000..35500d7 --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml.cs b/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml.cs new file mode 100644 index 0000000..83a5a4c --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/MainWindow.xaml.cs @@ -0,0 +1,48 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Markup; + +namespace WPF基础_1_1_只使用代码方式创建; + +/// +/// Interaction logic for MainWindow.xaml +/// +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"; + } +} \ No newline at end of file diff --git a/WPF基础-1-1-只使用代码方式创建/WPF基础-1-1-只使用代码方式创建.csproj b/WPF基础-1-1-只使用代码方式创建/WPF基础-1-1-只使用代码方式创建.csproj new file mode 100644 index 0000000..13954c0 --- /dev/null +++ b/WPF基础-1-1-只使用代码方式创建/WPF基础-1-1-只使用代码方式创建.csproj @@ -0,0 +1,12 @@ + + + + WinExe + net8.0-windows + WPF基础_1_1_只使用代码方式创建 + enable + enable + true + + + diff --git a/WPF基础.sln b/WPF基础.sln index 120efdb..c172e21 100644 --- a/WPF基础.sln +++ b/WPF基础.sln @@ -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