WPF初级界面设计

#WPF界面 #WPF初级     灵感来源于B站重庆教主的视频链接地址

首先看一下效果图,这是管理员登录进区的界面,或者你也可以直接设置为主界面。

本章讲如何用WPF来完成这个界面设计,它重点包括一些应用资源词典的样式,插入图片。我用的软件是VS2022版本

在Mainwindow.xaml窗口进行设计

第一步,整体布局为两行两列

在Grid容器中进行行与列的定义,如图下

第二步,添加图片资源 打开阿里图标网站,选择你想要的全部图标,然后点击下载代码,下载完成之后,新建Icon文件夹右击添加现有项,找到你下载的图标代码,添加字体文件。

第三步 完成左上角设计

第四步(1) 新建资源文件夹添加一个资源词典

(2)添加之后设置样式和属性

(3)在App.xaml文件中添加资源词典,资源引用

(4)完成如下图设计

第五步完成菜单列表设计

添加资源词典ExpanderDictionary和RadioButtonMenuStyle

(1)ExpanderDictionary样式设置

(2)RadioButtonMenuStyle样式设置(3)引用资源词典

(4)完成如下图设计菜单栏列表

当鼠标移到时<!--主菜单-->
<Grid Grid.Row=" 1" Grid.Column=" 0" Tag="菜单" Background="#273542" >
    <Grid.RowDefinitions >
        <RowDefinition Height="auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <Border  Height="5" Background=" #1A2327" VerticalAlignment="Center" >
        <TextBlock Text=" -----------" FontSize=" 15" Foreground="Black"  VerticalAlignment="Center"  />
    </Border >
  
    <StackPanel Grid.Row=" 1" >
        <Expander  Background=" #1D282B"  ExpandDirection="Down"  SnapsToDevicePixels="True" VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}">
            <Expander.Header >
                <StackPanel   Background="Transparent"  Height="40" Orientation="Horizontal" >
                    <TextBlock Margin=" 10 0 0 0"  Width="auto" FontSize=" 22" Text="&#xe602;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                    <TextBlock Width=" 200" FontSize=" 18" Text=" 控制台首页"  Foreground=" #918C8C" VerticalAlignment="Center"/>
                </StackPanel >
            </Expander.Header >
            <Expander.Content>
                <StackPanel Background=" #1A2327" >
                    <RadioButton Height=" 25"  Style="{StaticResource RadioButton.Over}" >
                        <StackPanel   Background="Transparent"  Height="20" Orientation="Horizontal" >
                            <TextBlock Margin=" 10 0 10 0"  Width="auto" FontSize=" 15" Text="&#xe60c;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                            <TextBlock Width=" 200" FontSize=" 15" Text=" 物资设置" Foreground="White"  VerticalAlignment="Center"  HorizontalAlignment="Left"  />
                        </StackPanel >
                    </RadioButton>
                    <RadioButton Height=" 25"  Style="{StaticResource RadioButton.Over}"  >
                        <StackPanel   Background="Transparent"  Height="20" Orientation="Horizontal" >
                            <TextBlock Margin=" 10 0 10 0"  Width="auto" FontSize=" 15" Text="&#xe60c;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                            <TextBlock Width=" 200" FontSize=" 15" Text=" 物资登记" Foreground="White"  VerticalAlignment="Center"  HorizontalAlignment="Left"  />
                        </StackPanel >
                    </RadioButton>
                    <RadioButton Height=" 25" Style="{StaticResource RadioButton.Over}">
                        <StackPanel   Background="Transparent"  Height="20" Orientation="Horizontal" >
                            <TextBlock Margin=" 10 0 10 0"  Width="auto" FontSize=" 15" Text="&#xe63a;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                            <TextBlock Width=" 200" FontSize=" 15" Text=" 供应商设置" Foreground="White"  VerticalAlignment="Center"  HorizontalAlignment="Left"  />
                        </StackPanel >
                    </RadioButton>
                    <RadioButton Height=" 25" Style="{StaticResource RadioButton.Over}"  >
                        <StackPanel   Background="Transparent"  Height="20" Orientation="Horizontal" >
                            <TextBlock Margin=" 10 0 10 0"  Width="auto" FontSize=" 15" Text="&#xe634;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                            <TextBlock Width=" 200" FontSize=" 15" Text=" 仓库设置" Foreground="White"  VerticalAlignment="Center"  HorizontalAlignment="Left"  />
                        </StackPanel >
                    </RadioButton>
                    <RadioButton Height=" 25" Style="{StaticResource RadioButton.Over}">
                        <StackPanel   Background="Transparent"  Height="20" Orientation="Horizontal" >
                            <TextBlock Margin=" 10 0 10 0"  Width="auto" FontSize=" 15" Text="&#xe634;" FontFamily="./Icon/#iconfont"  Foreground="#2D5EA3"   VerticalAlignment="Center"/>
                            <TextBlock Width=" 200" FontSize=" 15" Text=" 规格设置" Foreground="White"  VerticalAlignment="Center"  HorizontalAlignment="Left"  />
                        </StackPanel >
                    </RadioButton>

                </StackPanel>
            </Expander.Content>
        </Expander >
    </StackPanel >
</Grid >

关于中间的舞台设计我们留到下一章

WPF(Windows Presentation Foundation)是一个用于创建可视化界面的技术,它提供了丰富的控件和布局选项,使界面设计变得简单而灵活。 首先,在WPF中,可以使用XAML(eXtensible Application Markup Language)语言来定义界面的结构和外观。通过使用XAML,您可以使用标签和属性的方式来创建界面元素,例如按钮、文本框、列表框等。这种声明式的方式使得界面设计变得直观和易于理解。 其次,WPF提供了许多内置的样式和模板,可以轻松地对界面元素进行自定义和美化。您可以使用样式来定义按钮的颜色、文本框的边框样式等;也可以使用模板来完全改变控件的外观和布局方式。这样,您可以根据应用程序的需求和风格要求来设计界面,使其与众不同。 此外,WPF还支持数据绑定,使界面和数据之间的绑定更加简单和自动化。您可以绑定界面元素的属性到数据源,当数据源的值改变时,界面元素也会自动更新。这样,您可以实现动态更新界面的功能,无需手动干预。 最后,WPF还提供了强大的布局管理器,例如StackPanel、Grid和DockPanel等。这些布局管理器可以帮助您在界面中灵活组织和排列控件,使其具有良好的可读性和可维护性。您可以使用这些布局管理器来创建简单的界面,例如在窗口中添加按钮和文本框,以及控制它们的布局方式。 总的来说,WPF简单的界面设计要是通过使用XAML语言、内置样式和模板、数据绑定以及布局管理器等功能来实现。这些功能使得界面设计更加直观、灵活和易于维护,可以满足各种应用程序的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值