当前位置: 首页 > web >正文

WPF【11_3】WPF实战-重构与美化(可复用的UI组件)

11-7 【UI】美化主页面
04:40
既然要使用到图片,肯定要把图片设为静态资源保存到项目中。图片复制到VS项目中后,右击图片 - Properties,找到 Build Action: Resource ,这个图片就可以被WPF程序打包了。

UI重新布局:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="240"/>
        <ColumnDefinition Width="280"/>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    
    <!--header-->
    <Border Grid.ColumnSpan="3" Background="#7f3089">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <Image Height="90" Margin="5" Source="/Images/logo.jpg"/>
            <TextBlock Text="WPF客户管理系统" FontSize="40" VerticalAlignment="Center" Foreground="#ffffff"/>
        </StackPanel>
    </Border>

    <StackPanel Grid.Row="1" Grid.Column="0">
        <Button Content="添加客户"/>
        <ListView />
    </StackPanel>

    <StackPanel Grid.Row="1" Grid.Column="1">
        <TextBlock Text="姓名" Margin="10 10 10 0"/>
        <TextBox Margin="10" />
        <TextBlock Text="身份证" Margin="10 10 10 0"/>
        <TextBox Margin="10" />
        <TextBlock Text="地址" Margin="10 10 10 0"/>
        <TextBox Margin="10" />
        <Button Content="保存" Margin="10 10 10 30" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
    </StackPanel>

    <StackPanel Grid.Row="1" Grid.Column="2">
        <ListView />
        <TextBlock Text="添加新预约" />
        <DatePicker Margin="10" />
        <Button Content="预约" />
    </StackPanel>
    
</Grid>

11-8 【UI】组件化布局

如何把上节的 <!--header--> 提取出来,通过 UserControl 封装为可复用的UI组件。

在文件夹“”右击 - Add - New Item ,左侧选择 WPF - User Control (WPF) ,命名为:HeaderControl

--\Controls\HeaderControl.xaml
<UserControl x:Class="WPF_CMS.Controls.HeaderControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WPF_CMS.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Border Background="#7f3089">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <Image Height="90" Margin="5" Source="/Images/logo.jpg"/>
            <TextBlock Text="WPF客户管理系统" FontSize="40" VerticalAlignment="Center" Foreground="#ffffff"/>
        </StackPanel>
    </Border>
</UserControl>


--\WPF_CMS\MainWindow.xaml
<Window x:Class="WPF_CMS.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"
    xmlns:local="clr-namespace:WPF_CMS" 
    xmlns:controls="clr-namespace:WPF_CMS.Controls"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid>
    …………
    <!--header-->
    <controls:HeaderControl Grid.ColumnSpan="3"/>
    …………
</Grid>
</Window>


修改后,未编译时代码显示依然报错,重新构建(编译)一下代码就可以了。

http://www.xdnf.cn/news/9292.html

相关文章:

  • 编写第一个ros程序
  • 【Python训练营打卡】day37 @浙大疏锦行
  • 吉林省CCPC与全国邀请赛(东北地区赛)游记
  • 把 CURSOR 的工具活动栏改成和 VSCODE 一样的左侧展示
  • 防爆手机VS普通手机,区别在哪里?
  • Python实例题:使用Python定制词云
  • 基于深度学习的语音识别系统设计与实现
  • OpenCV CUDA模块图像处理------颜色空间处理之用于执行伽马校正(Gamma Correction)函数gammaCorrection()
  • Jenkins分配对应项目权限与用户管理
  • Linux中的常用命令
  • JSON全面解析
  • Qt基础终结篇:从文件操作到多线程异步UI,深度解析核心要点
  • -资产收集篇FridaHOOKXposed证书提取单向双向检验抓包
  • Logi鼠标切换桌面失效
  • ubuntu2x.xx网络不通如何解决
  • 《计算机组成原理》第 9 章 - 控制单元的功能
  • 光电赋能低空场景,灵途科技助力无人机持续升级
  • 红黑树,B树,二叉树之间的不同
  • 【监控】Prometheus中的告警机制介绍
  • 异常:UnsupportedOperationException: null
  • 【Java开发日记】说一说序列化与反序列化中存在的问题
  • 前端 reconnecting-websocket 包
  • 【AI工具应用】使用 trae 实现 word 转成 html
  • 实验设计与分析(第6版,Montgomery)第3章单因子实验:方差分析3.11思考题3.4 R语言解题
  • Python训练打卡Day35
  • vLLM 核心技术 PagedAttention 原理详解
  • SLOT:测试时样本专属语言模型优化,让大模型推理更精准!
  • 对于ARM开发各种手册的分类
  • 计算机网络-网络层
  • 赋能低空经济 | 奇妙智能已掌握AI+无人机智慧巡检技术