开始使用Panuon开源界面库情况设置并手写VS2019高仿界面 ...

打印 上一主题 下一主题

主题 1026|帖子 1026|积分 3078


  • 1. Panuon情况设置

    • 1.1. 通过Nuget 安装 Panuon.WPF.UI
    • 1.2. xaml引用定名空间
    • 1.3. using Panuon.WPF.UI;

  • 2. VS2019 view

    • 2.1. 设置窗体尺寸和title
    • 2.2. 添加静态资源

      • 2.2.1. 什么是静态资源

    • 2.3. 主Grid

      • 2.3.1. 盒子模型
      • 2.3.2. 嵌套布局


  • 3. 总结
1. Panuon情况设置

1.1. 通过Nuget 安装 Panuon.WPF.UI

现在最新的是1.2.4.9,点击安装即可

1.2. xaml引用定名空间

修改MainWindow.xaml,引用定名空间xmlns:pu="clr-namespaceanuon.WPF.UI;assembly=Panuon.WPF.UI"
然后把Window标签改为pu:WindowX

1.3. using Panuon.WPF.UI;

在MainWindow.cs中引用定名空间using Panuon.WPF.UI;
同样,必要把基类Window 改为 WindowX, 这样窗体酿成了Panuon 窗体了,很简单。
2. VS2019 view

下面我们用panuon开发一个高仿VS2019启动界面,终极制品如下:

2.1. 设置窗体尺寸和title

新建WPF工程,按第1节设置panuon情况,然后在pu:WindowX继续添加属性
  1. Title="Visual Studio (SIM)"
  2. Height="630"
  3. Width="1058"
  4. MinHeight="630"
  5. MinWidth="1058"
  6. Background="#252526"
  7. BorderBrush="#3E3E45"
  8. BorderThickness="1"
  9. Foreground="#F1F1F1"
复制代码
2.2. 添加静态资源

2.2.1. 什么是静态资源

资源可以分为静态资源或动态资源举行引用。
分别是通过使用 StaticResource 标记扩展或 DynamicResource 标记扩展完成的。
StaticResource的用法:
通过更换已界说资源的值(x:Key)来为 XAML 属性提供值。
这里添加静态资源就是可以对单个控件的样式单独控制,定制化。为后面的控件样式所用。
  1. <pu:WindowX.Resources>
  2.     <Style x:Key="SearchComboBoxStyle"
  3.        TargetType="ComboBox"
  4.        BasedOn="{StaticResource {x:Type ComboBox}}">
  5.         <Setter Property="pu:ComboBoxHelper.HoverBorderBrush"
  6.             Value="#007ACC" />
  7.         <Setter Property="pu:ComboBoxHelper.FocusedBorderBrush"
  8.             Value="#007ACC" />
  9.         <Setter Property="Height"
  10.             Value="35" />
  11.         <Setter Property="Width"
  12.             Value="320" />
  13.         <Setter Property="Background"
  14.             Value="#333337" />
  15.         <Setter Property="BorderBrush"
  16.             Value="#3F3F46" />
  17.         <Setter Property="Foreground"
  18.             Value="#F1F1F1" />
  19.     </Style>
  20.     <Style x:Key="CardButtonStyle"
  21.        TargetType="Button"
  22.        BasedOn="{StaticResource {x:Type Button}}">
  23.         <Setter Property="pu:IconHelper.FontFamily"
  24.             Value="{StaticResource PanuonIconFont}" />
  25.         <Setter Property="pu:IconHelper.FontSize"
  26.             Value="30" />
  27.         <Setter Property="pu:IconHelper.VerticalAlignment"
  28.             Value="Top" />
  29.         <Setter Property="pu:IconHelper.Margin"
  30.             Value="7,2,17,0" />
  31.         <Setter Property="pu:ButtonHelper.HoverBackground"
  32.             Value="#3F3F40" />
  33.         <Setter Property="pu:ButtonHelper.ClickBackground"
  34.             Value="{x:Null}" />
  35.         <Setter Property="Foreground"
  36.             Value="#F1F1F1" />
  37.         <Setter Property="Background"
  38.             Value="#333337" />
  39.         <Setter Property="Padding"
  40.             Value="10,7,10,10" />
  41.         <Setter Property="Height"
  42.             Value="75" />
  43.         <Setter Property="VerticalContentAlignment"
  44.             Value="Stretch" />
  45.         <Setter Property="HorizontalContentAlignment"
  46.             Value="Stretch" />
  47.     </Style>
  48.     <Style x:Key="LinkButtonStyle"
  49.        TargetType="Button"
  50.        BasedOn="{StaticResource {x:Type Button}}">
  51.         <Setter Property="pu:IconHelper.FontFamily"
  52.             Value="{StaticResource PanuonIconFont}" />
  53.         <Setter Property="pu:ButtonHelper.HoverBackground"
  54.             Value="{x:Null}" />
  55.         <Setter Property="pu:ButtonHelper.ClickBackground"
  56.             Value="{x:Null}" />
  57.         <Setter Property="Foreground"
  58.             Value="#0097FB" />
  59.         <Setter Property="Background"
  60.             Value="{x:Null}" />
  61.         <Setter Property="Cursor"
  62.             Value="Hand" />
  63.         <Setter Property="VerticalContentAlignment"
  64.             Value="Stretch" />
  65.         <Setter Property="HorizontalContentAlignment"
  66.             Value="Stretch" />
  67.         <Style.Triggers>
  68.             <Trigger Property="IsMouseOver"
  69.                  Value="True">
  70.                 <Setter Property="ContentTemplate">
  71.                     <Setter.Value>
  72.                         <DataTemplate>
  73.                             <TextBlock Text="{Binding}"
  74.                                    TextDecorations="Underline"/>
  75.                         </DataTemplate>
  76.                     </Setter.Value>
  77.                 </Setter>
  78.             </Trigger>
  79.         </Style.Triggers>
  80.     </Style>
  81.     <Style x:Key="ProjectListBoxStyle"
  82.        TargetType="ListBox"
  83.        BasedOn="{StaticResource {x:Type ListBox}}">
  84.         <Setter Property="pu:IconHelper.FontFamily"
  85.             Value="{StaticResource PanuonIconFont}" />
  86.         <Setter Property="pu:IconHelper.Width"
  87.             Value="25" />
  88.         <Setter Property="pu:IconHelper.Height"
  89.             Value="25" />
  90.         <Setter Property="pu:IconHelper.VerticalAlignment"
  91.             Value="Top" />
  92.         <Setter Property="pu:IconHelper.Margin"
  93.             Value="0,-15,7,0" />
  94.         <Setter Property="pu:ListBoxHelper.ItemsHeight"
  95.             Value="65" />
  96.         <Setter Property="pu:ListBoxHelper.ItemsPadding"
  97.             Value="10,0,10,0" />
  98.         <Setter Property="pu:ListBoxHelper.ItemsHoverBackground"
  99.             Value="#3F3F40" />
  100.         <Setter Property="pu:ListBoxHelper.ItemsSelectedBackground"
  101.             Value="{x:Null}" />
  102.         <Setter Property="Foreground"
  103.             Value="#F1F1F1" />
  104.         <Setter Property="Background"
  105.             Value="Transparent" />
  106.         <Setter Property="BorderThickness"
  107.             Value="0" />
  108.         <Setter Property="VerticalContentAlignment"
  109.             Value="Center" />
  110.         <Setter Property="HorizontalContentAlignment"
  111.             Value="Stretch" />
  112.     </Style>
  113. </pu:WindowX.Resources>
复制代码
2.3. 主Grid

2.3.1. 盒子模型

主Grid里面的布局必要手写,手写必要有一定布局的基础。如果不是很清楚必要先相识下盒子模型。
盒子模型最开始是应用于网页布局,将页面中全部元素都看作是一个盒子,盒子都包含以下几个属性:
width 宽度
height 高度
border 边框——围绕在内边距和内容外的边框
padding 内边距——清除内容四周的区域,内边距是透明的
margin 外边距——清除边框外的区域,外边距是透明的
content 内容——盒子的内容,显示文本和图像

2.3.2. 嵌套布局


用xaml写布局,当层级嵌套比力深,比力复杂的时间本身都会很晕,这里有个小本领我经常用,就是给背景/边框标红,这样能直观看到当前的嵌套到哪里了。等找到本身的定位后,在把红色标记去掉。
<Grid Margin="55,0,65,35" Background="Red">
完整的Grid布局代码:
  1. <Grid Margin="55,0,65,35">
  2.     <Grid.RowDefinitions>
  3.         <RowDefinition Height="Auto"/>
  4.         <RowDefinition />
  5.     </Grid.RowDefinitions>
  6.     <TextBlock Text="Visual Studio 2019 (SIM)"
  7.            FontSize="33"/>
  8.     <Grid Grid.Row="1">
  9.         <Grid.ColumnDefinitions>
  10.             <ColumnDefinition />
  11.             <ColumnDefinition Width="30"/>
  12.             <ColumnDefinition Width="0.6*" />
  13.         </Grid.ColumnDefinitions>
  14.         <Grid.RowDefinitions>
  15.             <RowDefinition Height="Auto"/>
  16.             <RowDefinition />
  17.         </Grid.RowDefinitions>
  18.         <TextBlock Margin="0,30,0,0"
  19.                Text="Open recent"
  20.                FontSize="20" />
  21.         <Grid Grid.Row="1">
  22.             <Grid.RowDefinitions>
  23.                 <RowDefinition Height="Auto" />
  24.                 <RowDefinition />
  25.             </Grid.RowDefinitions>
  26.             <ComboBox Margin="0,15,0,0"
  27.                   HorizontalAlignment="Left"
  28.                   IsEditable="True"
  29.                   Style="{StaticResource SearchComboBoxStyle}"
  30.                   pu:ComboBoxHelper.Watermark="Search recent" />
  31.             <ListBox Grid.Row="1"
  32.                  Margin="0,15,0,0"
  33.                  Style="{StaticResource ProjectListBoxStyle}">
  34.                 <ListBoxItem pu:ListBoxItemHelper.Icon="/Samples;component/Resources/WebForms.png">
  35.                     <Grid>
  36.                         <Grid.RowDefinitions>
  37.                             <RowDefinition Height="Auto"/>
  38.                             <RowDefinition Height="Auto"/>
  39.                         </Grid.RowDefinitions>
  40.                         <TextBlock FontSize="14"
  41.                                FontWeight="Bold"
  42.                                Text="ProjectA.sln" />
  43.                         <TextBlock VerticalAlignment="Center"
  44.                                HorizontalAlignment="Right"
  45.                                Foreground="#C6C8D2"
  46.                                Text="2021/4/12 12:00" />
  47.                         <TextBlock Grid.Row="1"
  48.                                Margin="0,8,0,0"
  49.                                Text="D:\ProjectA"
  50.                                TextTrimming="CharacterEllipsis"
  51.                                Foreground="#C6C8D2" />
  52.                     </Grid>
  53.                 </ListBoxItem>
  54.                 <ListBoxItem pu:ListBoxItemHelper.Icon="/Samples;component/Resources/WebForms.png">
  55.                     <Grid>
  56.                         <Grid.RowDefinitions>
  57.                             <RowDefinition Height="Auto" />
  58.                             <RowDefinition Height="Auto" />
  59.                         </Grid.RowDefinitions>
  60.                         <TextBlock FontSize="14"
  61.                                FontWeight="Bold"
  62.                                Text="ProjectB.sln" />
  63.                         <TextBlock VerticalAlignment="Center"
  64.                                HorizontalAlignment="Right"
  65.                                Foreground="#C6C8D2"
  66.                                Text="2021/4/12 12:00" />
  67.                         <TextBlock Grid.Row="1"
  68.                                Margin="0,8,0,0"
  69.                                Text="D:\ProjectB"
  70.                                TextTrimming="CharacterEllipsis"
  71.                                Foreground="#C6C8D2" />
  72.                     </Grid>
  73.                 </ListBoxItem>
  74.             </ListBox>
  75.         </Grid>
  76.         <TextBlock Grid.Column="2"
  77.                Margin="0,30,0,0"
  78.                Text="Get started"
  79.                FontSize="20" />
  80.         <StackPanel Grid.Column="2"
  81.                 Grid.Row="1"
  82.                 Margin="0,15,0,0">
  83.             <Button  Style="{StaticResource CardButtonStyle}"
  84.                  pu:ButtonHelper.Icon="&#xe941;">
  85.                 <StackPanel>
  86.                     <TextBlock FontSize="18"
  87.                            Text="Connect to a codespace"/>
  88.                     <TextBlock Margin="0,5,0,0"
  89.                            Text="Create and manage cloud-powered development environments"
  90.                            TextWrapping="Wrap"
  91.                            Foreground="#C6C8D2"/>
  92.                 </StackPanel>
  93.             </Button>
  94.             <Button Margin="0,5,0,0"
  95.                 Style="{StaticResource CardButtonStyle}"
  96.                  pu:ButtonHelper.Icon="&#xe94d;">
  97.                 <StackPanel>
  98.                     <TextBlock FontSize="18"
  99.                            Text="Clone a repository" />
  100.                     <TextBlock Margin="0,5,0,0"
  101.                            Text="Get code from an online repository like GitHub or Azure DevOps"
  102.                            TextWrapping="Wrap"
  103.                            Foreground="#C6C8D2" />
  104.                 </StackPanel>
  105.             </Button>
  106.             <Button Margin="0,5,0,0"
  107.                 Style="{StaticResource CardButtonStyle}"
  108.                 pu:ButtonHelper.Icon="&#xe951;">
  109.                 <StackPanel>
  110.                     <TextBlock FontSize="18"
  111.                            Text="Open a project or solution" />
  112.                     <TextBlock Margin="0,5,0,0"
  113.                            Text="Open a local Visual Studio project or .sln file"
  114.                            TextWrapping="Wrap"
  115.                            Foreground="#C6C8D2" />
  116.                 </StackPanel>
  117.             </Button>
  118.             <Button Margin="0,5,0,0"
  119.                 Style="{StaticResource CardButtonStyle}"
  120.                 pu:ButtonHelper.Icon="&#xe956;">
  121.                 <StackPanel>
  122.                     <TextBlock FontSize="18"
  123.                            Text="Open a local folder" />
  124.                     <TextBlock Margin="0,5,0,0"
  125.                            Text="Navigate and edit code within any folder"
  126.                            TextWrapping="Wrap"
  127.                            Foreground="#C6C8D2" />
  128.                 </StackPanel>
  129.             </Button>
  130.             <Button Margin="0,5,0,0"
  131.                 Style="{StaticResource CardButtonStyle}"
  132.                 pu:ButtonHelper.Icon="&#xe960;">
  133.                 <StackPanel>
  134.                     <TextBlock FontSize="18"
  135.                            Text="Create a new project" />
  136.                     <TextBlock Margin="0,5,0,0"
  137.                            Text="Choose a project template with code scaffolding to get started"
  138.                            TextWrapping="Wrap"
  139.                            Foreground="#C6C8D2" />
  140.                 </StackPanel>
  141.             </Button>
  142.             <StackPanel Margin="0,10,0,0"
  143.                     HorizontalAlignment="Center"
  144.                     Orientation="Horizontal">
  145.                 <Button Style="{StaticResource LinkButtonStyle}"
  146.                     Content="Continue without code" />
  147.                 <TextBlock Text="&#xe90e;"
  148.                        VerticalAlignment="Center"
  149.                        Foreground="#0097FB"
  150.                        FontFamily="{StaticResource PanuonIconFont}"/>
  151.             </StackPanel>
  152.         </StackPanel>
  153.     </Grid>
  154. </Grid>
复制代码
3. 总结

Panuon.WPF.UI 是一个适用于定制个性化UI界面的组件库。它能资助你快速完成样式和控件的UI设计,而不必深入相识WPF的 ControlTemplate 、 Storyboard 等知识。
比方,在原生WPF中下,如果你想要修改 Button 按钮 控件的悬浮背景色,你必要修改按钮的 Style 属性,并编写 Trigger 和 Storyboard 来实现悬浮渐变效果。如果你想要更复杂的效果,你可能还必要编写内部的ControlTemplate模板。但现在, Panuon.WPF.UI 为你提供了一个更简单的方式。你只必要在 Button 按钮 控件上添加一条 pu:ButtonHelper.HoverBackground="#FF0000" 属性,即可实现背景色悬浮渐变到红色的效果。Panuon.WPF.UI为每一种控件都提供了大量的属性,使你能够方便地修改WPF中没有直接提供,但在UI设计中非经常用的效果,这有助于你快速地完成UI设计(尤其是在你有设计图的情况下)。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宝塔山

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表