diff --git a/WPF基础-1-2-和xaml一起创建/App.xaml b/WPF基础-1-2-和xaml一起创建/App.xaml new file mode 100644 index 0000000..e37b188 --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WPF基础-1-2-和xaml一起创建/App.xaml.cs b/WPF基础-1-2-和xaml一起创建/App.xaml.cs new file mode 100644 index 0000000..d4060db --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/App.xaml.cs @@ -0,0 +1,12 @@ +using System.Configuration; +using System.Data; +using System.Windows; + +namespace WPF基础_1_2_和xaml一起创建; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ +} \ No newline at end of file diff --git a/WPF基础-1-2-和xaml一起创建/AssemblyInfo.cs b/WPF基础-1-2-和xaml一起创建/AssemblyInfo.cs new file mode 100644 index 0000000..521046e --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/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-2-和xaml一起创建/MainWindow.xaml b/WPF基础-1-2-和xaml一起创建/MainWindow.xaml new file mode 100644 index 0000000..e1e5222 --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/WPF基础-1-2-和xaml一起创建/MainWindow.xaml.cs b/WPF基础-1-2-和xaml一起创建/MainWindow.xaml.cs new file mode 100644 index 0000000..6880c52 --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/MainWindow.xaml.cs @@ -0,0 +1,49 @@ +using System.IO; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WPF基础_1_2_和xaml一起创建; + +/// +/// Interaction logic for MainWindow.xaml +/// +public partial class MainWindow : Window +{ + + public MainWindow() + { + InitializeComponent(); + } + + public MainWindow(string xamlFile) + { + Width = Height = 285; + Left = Top = 100; + Title = "混合xaml"; + + DependencyObject rootElement ; + using (var fileStream = new FileStream(xamlFile,FileMode.Open)) + { + rootElement = (DependencyObject)XamlReader.Load(fileStream); + } + + Content = rootElement; + + _button =(Button) LogicalTreeHelper.FindLogicalNode(rootElement,"_button"); + + _button.Click += Button_OnClick; + } + private void Button_OnClick(object sender, RoutedEventArgs eventArgs) + { + _button!.Content = "栓Q"; + } +} \ No newline at end of file diff --git a/WPF基础-1-2-和xaml一起创建/WPF基础-1-2-和xaml一起创建.csproj b/WPF基础-1-2-和xaml一起创建/WPF基础-1-2-和xaml一起创建.csproj new file mode 100644 index 0000000..508afbb --- /dev/null +++ b/WPF基础-1-2-和xaml一起创建/WPF基础-1-2-和xaml一起创建.csproj @@ -0,0 +1,12 @@ + + + + WinExe + net8.0-windows + WPF基础_1_2_和xaml一起创建 + enable + enable + true + + + diff --git a/WPF基础.sln b/WPF基础.sln index c172e21..5a447ae 100644 --- a/WPF基础.sln +++ b/WPF基础.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1", "WPF基础-1\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1-1-只使用代码方式创建", "WPF基础-1-1-只使用代码方式创建\WPF基础-1-1-只使用代码方式创建.csproj", "{BD355183-DF6F-49EC-A933-0B32280BC5B6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF基础-1-2-和xaml一起创建", "WPF基础-1-2-和xaml一起创建\WPF基础-1-2-和xaml一起创建.csproj", "{BEC5A610-FCE9-4A38-AE54-E1C516CED5E6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {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 + {BEC5A610-FCE9-4A38-AE54-E1C516CED5E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEC5A610-FCE9-4A38-AE54-E1C516CED5E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEC5A610-FCE9-4A38-AE54-E1C516CED5E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEC5A610-FCE9-4A38-AE54-E1C516CED5E6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal