赞
踩
界面设计源码地址:https://download.csdn.net/download/yigu4011/88011184
1、Nuget安装MaterialDesignThemes框架,安装LiveCharts、LiveCharts.Wpf(用来添加曲线,也可以下载LiveCharts.dll、LiveCharts.Wpf.dll,然后引用DLL)
2、打开阿里巴巴素材库,下载素材,解压素材,将素材文件iconfont.ttf添加到项目
3、App.xaml中添加资源代码:
- <Application x:Class="WpfApp1.App"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:WpfApp1"
- StartupUri="MainWindow.xaml">
- <Application.Resources>
- <ResourceDictionary>
- <ResourceDictionary.MergedDictionaries>
- <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
- <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
- <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
- <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
- </ResourceDictionary.MergedDictionaries>
- </ResourceDictionary>
- </Application.Resources>
- </Application>
4、在MainWindow.xaml添加MaterialDesignThemes、LiveCharts、LiveCharts.Wpf的引用
- xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
- xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
5、左边菜单栏关键性代码如下:(全部源码可去上方CSDN代码地址自由下载)
- <StackPanel Grid.Row="1">
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="#9C27B3"
- BorderBrush="#9C27B3">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="White"
- Text="󰁰" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="White"
- Text="Surface" />
- </StackPanel>
- </Button>
-
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="Transparent"
- BorderBrush="Transparent">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="#848484"
- Text="" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="#848484"
- Text="Bing" />
- </StackPanel>
- </Button>
-
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="Transparent"
- BorderBrush="Transparent">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="#848484"
- Text="" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="#848484"
- Text="Windows" />
- </StackPanel>
- </Button>
-
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="Transparent"
- BorderBrush="Transparent">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="#848484"
- Text="" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="#848484"
- Text="Xbox" />
- </StackPanel>
- </Button>
-
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="Transparent"
- BorderBrush="Transparent">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="#848484"
- Text="" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="#848484"
- Text="Hololens" />
- </StackPanel>
- </Button>
-
- <Button
- Width="250"
- Height="50"
- Margin="15,30"
- HorizontalContentAlignment="Left"
- materialDesign:ShadowAssist.ShadowDepth="Depth3"
- Background="Transparent"
- BorderBrush="Transparent">
- <StackPanel Orientation="Horizontal">
- <!-- 图标 -->
- <TextBlock
- FontFamily="/#iconfont"
- FontSize="26"
- Foreground="#848484"
- Text="" />
- <!-- 文字 -->
- <TextBlock
- Margin="15,0,0,0"
- VerticalAlignment="Center"
- Foreground="#848484"
- Text="Azure" />
- </StackPanel>
- </Button>
- </StackPanel>
6、右边显示关键代码如下:
- <UniformGrid Grid.Row="2" Columns="3">
- <Border
- Margin="20,20,20,20"
- Background="White"
- CornerRadius="5">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="1.7*" />
- <RowDefinition />
- </Grid.RowDefinitions>
-
- <Grid Margin="20,-20,20,10" Panel.ZIndex="1">
- <Grid.Effect>
- <DropShadowEffect
- BlurRadius="15"
- Direction="-90"
- Opacity=".2"
- RenderingBias="Quality"
- ShadowDepth="1" />
- </Grid.Effect>
- <Grid.Resources>
- <Style TargetType="lvc:ColumnSeries">
- <Setter Property="StrokeThickness" Value="0" />
- <Setter Property="Stroke" Value="White" />
- <Setter Property="Fill" Value="White" />
- <Setter Property="MaxColumnWidth" Value="5" />
- </Style>
- <Style TargetType="lvc:Axis">
- <Setter Property="FontSize" Value="12" />
- <Setter Property="Foreground" Value="#64FFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="Y">
- <Setter Property="IsMerged" Value="True" />
- <Setter Property="MaxValue" Value="10" />
- </Trigger>
- </Style.Triggers>
- </Style>
- <Style TargetType="lvc:Separator">
- <Setter Property="StrokeThickness" Value="1" />
- <Setter Property="Stroke" Value="#4BFFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="X">
- <Setter Property="IsEnabled" Value="False" />
- <Setter Property="Step" Value="1" />
- </Trigger>
- </Style.Triggers>
- </Style>
- </Grid.Resources>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height=".50*" />
- </Grid.RowDefinitions>
- <Border
- x:Name="Border1"
- Grid.Row="0"
- Grid.RowSpan="4"
- Background="White"
- CornerRadius="5" />
- <Border Grid.RowSpan="3" Background="#51AB54" />
- <lvc:CartesianChart
- Grid.Row="2"
- Margin="10,0,10,20"
- DataTooltip="{x:Null}"
- Hoverable="False">
- <lvc:CartesianChart.Series>
- <lvc:ColumnSeries Values="5,9,8,6,1,5,7,3,6,3" />
- </lvc:CartesianChart.Series>
- </lvc:CartesianChart>
- </Grid>
-
- <Grid Grid.Row="1">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="101*" />
- <ColumnDefinition Width="399*" />
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="1.5*" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <StackPanel
- Grid.ColumnSpan="2"
- VerticalAlignment="Bottom"
- Orientation="Vertical">
- <TextBlock
- Margin="20,0"
- FontSize="25"
- Foreground="#959595"
- Text="XBOX" />
- <TextBlock
- Margin="20,0"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="Get More Data" />
- <Border
- Margin="30,5,30,0"
- VerticalAlignment="Bottom"
- BorderBrush="DarkGray"
- BorderThickness="0,0,0,1" />
- </StackPanel>
- <TextBlock
- Grid.Row="1"
- Grid.ColumnSpan="2"
- Margin="20,0,20,0"
- VerticalAlignment="Center"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="updated 4 minutes ago" />
- </Grid>
- </Grid>
- </Border>
- <Border
- Margin="20,20,20,20"
- Background="White"
- CornerRadius="5">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="1.7*" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <Grid Margin="20,-20,20,10" Panel.ZIndex="1">
- <Grid.Effect>
- <DropShadowEffect
- BlurRadius="15"
- Direction="-90"
- Opacity=".2"
- RenderingBias="Quality"
- ShadowDepth="1" />
- </Grid.Effect>
- <Grid.Resources>
- <Style TargetType="lvc:ColumnSeries">
- <Setter Property="StrokeThickness" Value="0" />
- <Setter Property="Stroke" Value="White" />
- <Setter Property="Fill" Value="White" />
- <Setter Property="MaxColumnWidth" Value="5" />
- </Style>
- <Style TargetType="lvc:Axis">
- <Setter Property="FontSize" Value="12" />
- <Setter Property="Foreground" Value="#64FFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="Y">
- <Setter Property="IsMerged" Value="True" />
- <Setter Property="MaxValue" Value="10" />
- </Trigger>
- </Style.Triggers>
- </Style>
- <Style TargetType="lvc:Separator">
- <Setter Property="StrokeThickness" Value="1" />
- <Setter Property="Stroke" Value="#4BFFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="X">
- <Setter Property="IsEnabled" Value="False" />
- <Setter Property="Step" Value="1" />
- </Trigger>
- </Style.Triggers>
- </Style>
- </Grid.Resources>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height=".50*" />
- </Grid.RowDefinitions>
- <Border
- Grid.Row="0"
- Grid.RowSpan="4"
- Background="White"
- CornerRadius="5" />
- <Border
- Grid.Row="0"
- Grid.RowSpan="3"
- Background="#FD950E" />
-
- <lvc:CartesianChart
- Grid.Row="2"
- Margin="10,0,10,20"
- DataTooltip="{x:Null}"
- Hoverable="False">
- <lvc:CartesianChart.Series>
- <lvc:LineSeries Stroke="White" Values="5,9,8,6,1,5,7,3,6,3" />
- </lvc:CartesianChart.Series>
- </lvc:CartesianChart>
- </Grid>
-
- <Grid Grid.Row="1">
- <Grid.RowDefinitions>
- <RowDefinition Height="1.5*" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <StackPanel VerticalAlignment="Bottom" Orientation="Vertical">
- <TextBlock
- Margin="20,0"
- FontSize="25"
- Foreground="#959595"
- Text="Office" />
- <TextBlock
- Margin="20,0"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="Get More Data" />
- <Border
- Margin="30,5,30,0"
- VerticalAlignment="Bottom"
- BorderBrush="DarkGray"
- BorderThickness="0,0,0,1" />
- </StackPanel>
- <TextBlock
- Grid.Row="1"
- Margin="20,0"
- VerticalAlignment="Center"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="compaign sent 2 days ago" />
- </Grid>
- </Grid>
- </Border>
- <Border
- Margin="20,20,20,20"
- Background="White"
- CornerRadius="5">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="1.7*" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <Grid Margin="20,-20,20,10" Panel.ZIndex="1">
- <Grid.Effect>
- <DropShadowEffect
- BlurRadius="15"
- Direction="-90"
- Opacity=".2"
- RenderingBias="Quality"
- ShadowDepth="1" />
- </Grid.Effect>
- <Grid.Resources>
- <Style TargetType="lvc:ColumnSeries">
- <Setter Property="StrokeThickness" Value="0" />
- <Setter Property="Stroke" Value="White" />
- <Setter Property="Fill" Value="White" />
- <Setter Property="MaxColumnWidth" Value="5" />
- </Style>
- <Style TargetType="lvc:Axis">
- <Setter Property="FontSize" Value="12" />
- <Setter Property="Foreground" Value="#64FFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="Y">
- <Setter Property="IsMerged" Value="True" />
- <Setter Property="MaxValue" Value="10" />
- </Trigger>
- </Style.Triggers>
- </Style>
- <Style TargetType="lvc:Separator">
- <Setter Property="StrokeThickness" Value="1" />
- <Setter Property="Stroke" Value="#4BFFFFFF" />
- <Style.Triggers>
- <Trigger Property="AxisOrientation" Value="X">
- <Setter Property="IsEnabled" Value="False" />
- <Setter Property="Step" Value="1" />
- </Trigger>
- </Style.Triggers>
- </Style>
- </Grid.Resources>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="Auto" />
- <RowDefinition Height=".50*" />
- </Grid.RowDefinitions>
- <Border
- Grid.Row="0"
- Grid.RowSpan="4"
- Background="White"
- CornerRadius="5" />
- <Border
- Grid.Row="0"
- Grid.RowSpan="3"
- Background="#E94543" />
- <lvc:CartesianChart
- Grid.Row="2"
- Margin="0,0,0,0"
- DataTooltip="{x:Null}"
- Hoverable="True">
- <lvc:CartesianChart.Series>
- <lvc:LineSeries Stroke="White" Values="5,9,8,6,7,2,1,5,7,8," />
- </lvc:CartesianChart.Series>
- <lvc:CartesianChart.AxisX>
- <lvc:Axis MinValue="2" />
- </lvc:CartesianChart.AxisX>
- </lvc:CartesianChart>
-
- </Grid>
-
- <Grid Grid.Row="1">
- <Grid.RowDefinitions>
- <RowDefinition Height="1.5*" />
- <RowDefinition />
- </Grid.RowDefinitions>
- <StackPanel VerticalAlignment="Bottom" Orientation="Vertical">
- <TextBlock
- Margin="20,0"
- FontSize="25"
- Foreground="#959595"
- Text="Surface" />
- <TextBlock
- Margin="20,0"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="Get More Data" />
- <Border
- Margin="30,5,30,0"
- VerticalAlignment="Bottom"
- BorderBrush="DarkGray"
- BorderThickness="0,0,0,1" />
- </StackPanel>
- <TextBlock
- Grid.Row="1"
- Margin="20,0"
- VerticalAlignment="Center"
- FontSize="13"
- Foreground="#C8C8C8"
- Text="compaign sent 2 days ago" />
- </Grid>
- </Grid>
- </Border>
- </UniformGrid>
6、关键事件代码如下:
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
-
- Point _pressedPosition;
- bool _isDragMoved = false;
- private void Window_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
- {
- _pressedPosition = e.GetPosition(this);
- }
- private void Window_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if (Mouse.LeftButton == MouseButtonState.Pressed && _pressedPosition != e.GetPosition(this))
- {
- _isDragMoved = true;
- DragMove();
- }
- }
- private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if (_isDragMoved)
- {
- _isDragMoved = false;
- e.Handled = true;
- }
- }
-
-
- private void btnMin_Click(object sender, RoutedEventArgs e)
- {
- this.WindowState = WindowState.Minimized;
- }
-
- private void btnMax_Click(object sender, RoutedEventArgs e)
- {
- if (this.WindowState == WindowState.Maximized)
- {
- this.WindowState = WindowState.Normal;
- }
- else
- {
- this.WindowState = WindowState.Maximized;
- }
- }
-
- private void btnClose_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。