B站朝夕教育 【.NET9.0+WPF实战三类流程化业务逻辑控制】学习记录

播放地址:20241120-.NET9.0+WPF实战三类流程化业务逻辑控制-10_哔哩哔哩_bilibili

Nuget需要安装两个依赖

CommunityToolkit.Mvvm

Microsoft.Xaml.Behaviors.Wpf

第1-2课时主要是理论,略

第3课时,WPF中新增的主题设置

修改MainWindow.xaml文件中的代码为:

复制代码
 1 <Window x:Class="WpfApp1.Views.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6         xmlns:local="clr-namespace:WpfApp1"
 7         mc:Ignorable="d"
 8         Title="MainWindow" Height="450" Width="800" Background="White">
 9     <ScrollViewer>
10     <Grid>
11         <TabControl>
12             <TabItem Header="AAAA">
13                 <StackPanel>
14                     <Button Content="Button" />
15                     <Label Content="Label" />
16                     <CheckBox Content="CheckBox" />
17                     <RadioButton Content="RadioButton" />
18                     <ToggleButton Content="ToggleButton" />
19                     <ComboBox>
20                         <ComboBoxItem Content="AAA" />
21                         <ComboBoxItem Content="BBB" />
22                         <ComboBoxItem Content="CCC" />
23                         <ComboBoxItem Content="DDD" />
24                     </ComboBox>
25                     <ListBox>
26                         <ListBoxItem Content="AAAA" />
27                         <ListBoxItem Content="AAAA" />
28                         <ListBoxItem Content="AAAA" />
29                         <ListBoxItem Content="AAAA" />
30                         <ListBoxItem Content="AAAA" />
31                     </ListBox>
32                     <Calendar />
33                     <DatePicker />
34                 </StackPanel>
35             </TabItem>
36             <TabItem Header="BBB">
37 
38             </TabItem>
39             <TabItem Header="CCC">
40 
41             </TabItem>
42         </TabControl>
43 
44         </Grid>
45     </ScrollViewer>
46 </Window>
演示主题使用的代码
复制代码

在App.xaml文件中修改代码

增加 ResourceDictionary节点,及内容,内部包含多种不同风格,可以自己尝试切换

复制代码
 1 <Application x:Class="WpfApp1.App"
 2              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4              xmlns:local="clr-namespace:WpfApp1"
 5              StartupUri="Views/MainView.xaml">
 6     <Application.Resources>
 7         <ResourceDictionary>
 8             <ResourceDictionary.MergedDictionaries>
 9                 <ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" />
10                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Aero;component/Themes/Aero.NormalColor.xaml" />-->
11                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.AeroLite;component/Themes/AeroLite.NormalColor.xaml" />-->
12                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Classic;component/Themes/Classic.xaml" />-->
13                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Luna;component/Themes/Luna.HomeStead.xaml" />-->
14                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Luna;component/Themes/Luna.Metallic.xaml" />-->
15                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Luna;component/Themes/Luna.NormalColor.xaml" />-->
16                 <!--<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Royale;component/Themes/Royale.NormalColor.xaml" />-->
17             </ResourceDictionary.MergedDictionaries>
18         </ResourceDictionary>
19     </Application.Resources>
20 </Application>
WPF切换主题
复制代码

第4-5课时创建MainView.xaml窗口演示如何使用传统方法实现拖拽控件

  • 在窗口Window节点中设置属性WindowStartupLocation="CenterScreen",让窗口启动时在屏幕中间位置
  • 注意如果你的VS主题设置的是深色需要再再Window节点上增加Background="White"或者其他颜色,否则启动后背景黑色应用了上面的主题后很多效果看不到
  • xaml文件代码
    复制代码
     1 <Window x:Class="WpfApp1.MainView"
     2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     4         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     5         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     6         xmlns:local="clr-namespace:WpfApp1"
     7         mc:Ignorable="d"
     8         WindowStartupLocation="CenterScreen"
     9         Background="White"
    10         Title="MainView" Height="650" Width="1300">
    11     <Grid>
    12         <Grid.ColumnDefinitions>
    13             <ColumnDefinition Width="200" />
    14             <ColumnDefinition Width="300" />
    15             <ColumnDefinition />           
    16         </Grid.ColumnDefinitions>
    17         <ListView>
    18             <ListViewItem Content="AAA" PreviewMouseLeftButtonDown="ListViewItem_MouseLeftButtonDown"></ListViewItem>
    19             <ListViewItem Content="BBB" PreviewMouseLeftButtonDown="ListViewItem_MouseLeftButtonDown"></ListViewItem>
    20             <ListViewItem Content="CCC" PreviewMouseLeftButtonDown="ListViewItem_MouseLeftButtonDown"></ListViewItem>
    21             <ListViewItem Content="DDD" PreviewMouseLeftButtonDown="ListViewItem_MouseLeftButtonDown"></ListViewItem>
    22         </ListView>
    23         <ListBox Grid.Column="1" Drop="ListBox_Drop" AllowDrop="True"></ListBox>
    24     </Grid>
    25 </Window>
    复制代码
  • MainView.xaml.cs文件里新增代码
    复制代码
     1         private void ListViewItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
     2         {
     3             DragDrop.DoDragDrop((DependencyObject)sender, (sender as ListViewItem).Content, DragDropEffects.Copy);
     4         }
     5 
     6         private void ListBox_Drop(object sender, DragEventArgs e)
     7         {
     8             string value = e.Data.GetData(typeof(string)).ToString();
     9             (sender as ListBox).Items.Add(new ListBoxItem() { Content=value});
    10         }
    复制代码

     

posted @   uxinxin  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示