效果图:

ActiveFunItem.xaml代码:

<UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunItem"
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"
mc:Ignorable="d"
d:DesignHeight="74" d:DesignWidth="50">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding ItemWidth}"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
</Grid.RowDefinitions>
<Border Width="{Binding ItemWidth}" Height="{Binding ItemWidth}" Background="{Binding FillColor}" BorderBrush="{Binding BorderColor}" BorderThickness="2" CornerRadius="{Binding ItemWidthHalf}" >
<Border.ToolTip>
<ToolTip>
<ToolTip.Template>
<ControlTemplate>
<Border Background="#88333333" CornerRadius="4">
<TextBlock Margin="5" Foreground="#f2f2f2" Text="{Binding FunName}"></TextBlock>
</Border>
</ControlTemplate>
</ToolTip.Template>
</ToolTip>
</Border.ToolTip>
<Image Width="{Binding IconWidth}" Height="{Binding IconWidth}" Stretch="Fill" Source="{Binding Image}" VerticalAlignment="Center" HorizontalAlignment="Center"></Image>
</Border>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding Count}" Foreground="#008bf1" FontSize="20" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="次" Foreground="#008bf1" FontSize="20" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Grid>
</UserControl>

ActiveFunItem.xaml.cs代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace SunCreate.Vipf.Client.UI
{
/// <summary>
/// 图标控件
/// </summary>
public partial class ActiveFunItem : UserControl, INotifyPropertyChanged
{
private Thickness _OriginalMargin;
/// <summary>
/// 初始Margin
/// </summary>
public Thickness OriginalMargin
{
get
{
return _OriginalMargin;
}
set
{
_OriginalMargin = value;
OnPropertyChanged("OriginalMargin");
}
} private int _ItemWidth = ;
/// <summary>
/// 圆宽度
/// </summary>
public int ItemWidth
{
get
{
return _ItemWidth;
}
set
{
_ItemWidth = value;
OnPropertyChanged("ItemWidth"); ItemWidthHalf = ItemWidth / ;
IconWidth = (int)(ItemWidth * 0.65);
}
} private int _ItemWidthHalf = ;
/// <summary>
/// 圆宽度一半
/// </summary>
public int ItemWidthHalf
{
get
{
return _ItemWidthHalf;
}
set
{
_ItemWidthHalf = value;
OnPropertyChanged("ItemWidthHalf");
}
} private int _IconWidth = ;
/// <summary>
/// 图标宽度
/// </summary>
public int IconWidth
{
get
{
return _IconWidth;
}
set
{
_IconWidth = value;
OnPropertyChanged("IconWidth");
}
} private SolidColorBrush _FillColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9848"));
/// <summary>
/// 填充颜色
/// </summary>
public SolidColorBrush FillColor
{
get
{
return _FillColor;
}
set
{
_FillColor = value;
OnPropertyChanged("FillColor");
}
} private SolidColorBrush _BorderColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ed6900"));
/// <summary>
/// 边框颜色
/// </summary>
public SolidColorBrush BorderColor
{
get
{
return _BorderColor;
}
set
{
_BorderColor = value;
OnPropertyChanged("BorderColor");
}
} private ImageSource _Image = new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-人脸分析.png", UriKind.RelativeOrAbsolute));
/// <summary>
/// 图标的图片
/// </summary>
public ImageSource Image
{
get { return _Image; }
set
{
_Image = value;
OnPropertyChanged("Image");
}
} private int _Count = ;
/// <summary>
/// 活跃次数
/// </summary>
public int Count
{
get
{
return _Count;
}
set
{
_Count = value;
OnPropertyChanged("Count");
}
} private string _FunName;
/// <summary>
/// 功能名称
/// </summary>
public string FunName
{
get
{
return _FunName;
}
set
{
_FunName = value;
OnPropertyChanged("FunName");
}
} public ActiveFunItem()
{
InitializeComponent();
this.DataContext = this;
} #region INotifyPropertyChanged接口
public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion }
}

ActiveFunction.xaml代码:

<UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunction"
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:SunCreate.Vipf.Client.UI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
</Grid.RowDefinitions>
<Border CornerRadius="5 5 0 0" Background="#368bf0">
<StackPanel Orientation="Horizontal" Margin="10 0 0 0">
<Image Width="14" Source="/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/面板-活跃功能.png"></Image>
<TextBlock Margin="10 0 0 0" Text="活跃功能" FontSize="14" Foreground="#fff" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Border>
<Border Grid.Row="1" CornerRadius="0 0 5 5" Background="#ffffff" BorderThickness="1 0 1 1" BorderBrush="#dddddd" SnapsToDevicePixels="True">
<Grid>
<Viewbox x:Name="viewbox" Stretch="Fill" Height="260" Width="260">
<Canvas Width="320" Height="320">
<Grid>
<Grid Width="300" Height="300">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃总量.png"/>
</Grid.Background>
</Grid>
<Grid x:Name="container" Width="320" Height="320">
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="76,20,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="173,20,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="240,79,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="241,182,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="171,247,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="75,247,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="11,178,0,0"></local:ActiveFunItem>
<local:ActiveFunItem VerticalAlignment="Top" HorizontalAlignment="Left" Margin="12,82,0,0"></local:ActiveFunItem>
</Grid>
<TextBlock Text="{Binding Count}" FontSize="30" FontWeight="Bold" Foreground="#ff2121" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
</Grid>
</Canvas>
</Viewbox>
</Grid>
</Border>
</Grid>
</UserControl>

ActiveFunction.xaml.cs代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace SunCreate.Vipf.Client.UI
{
/// <summary>
/// 活跃功能
/// </summary>
public partial class ActiveFunction : UserControl, INotifyPropertyChanged
{
#region 字段属性
/// <summary>
/// 图标控件集合
/// </summary>
private List<ActiveFunItem> _list = new List<ActiveFunItem>(); /// <summary>
/// 图标背景颜色
/// </summary>
private SolidColorBrush[] _fillColorArr = new SolidColorBrush[] {
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9848")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff211b")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00d235")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#009df0"))
}; /// <summary>
/// 图标背景边框颜色
/// </summary>
private SolidColorBrush[] _borderColorArr = new SolidColorBrush[] {
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ed6900")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b40000")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00912b")),
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#0065d1"))
}; /// <summary>
/// 图标大小
/// </summary>
private int[] _widthArr = new int[] {
,
,
,
,
,
,
, }; /// <summary>
/// 位置数组
/// </summary>
private int[] _posArr = new int[] {
,
,
,
,
,
,
, }; /// <summary>
/// 功能名称图标集合
/// </summary>
private Dictionary<string, ImageSource> _dictNameIcon = new Dictionary<string, ImageSource>(); private int _Count;
/// <summary>
/// 活跃总量
/// </summary>
public int Count
{
get
{
return _Count;
}
set
{
_Count = value;
OnPropertyChanged("Count");
}
}
#endregion public ActiveFunction()
{
InitializeComponent();
this.DataContext = this; this.Count = ; //活跃总量 #region 功能名称图标集合(后期补充更多功能名称图标)
_dictNameIcon.Add("车辆分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-车辆分析.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("行为分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-行为分析.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("结构化分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-结构化分析.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("历史视频", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-历史视频.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("人脸分析", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-人脸分析.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("实时视频", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-实时视频.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("视频巡查", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-视频巡查.png", UriKind.RelativeOrAbsolute)));
_dictNameIcon.Add("资源申请", new BitmapImage(new Uri("/SunCreate.Vipf.Client.Resources;component/Image/_ZZ/ManagerMainPage/活跃功能-资源申请.png", UriKind.RelativeOrAbsolute)));
#endregion #region 初始化控件
int i = ;
foreach (ActiveFunItem item in container.Children)
{
item.OriginalMargin = new Thickness(item.Margin.Left + , item.Margin.Top + , , );
item.FillColor = _fillColorArr[i];
item.BorderColor = _borderColorArr[i];
_list.Add(item);
i++;
}
#endregion Statistic(); } #region 统计
/// <summary>
/// 统计
/// </summary>
public void Statistic()
{
#region 活跃功能活跃次数测试数据
Dictionary<string, int> dict = new Dictionary<string, int>();
dict.Add("人脸分析", );
dict.Add("行为分析", );
dict.Add("结构化分析", );
dict.Add("历史视频", );
dict.Add("实时视频", );
dict.Add("车辆分析", );
dict.Add("视频巡查", );
dict.Add("资源申请", );
#endregion #region 重新计算ActiveFunItem属性
List<KeyValuePair<string, int>> _sortedList = dict.ToList();
_sortedList.Sort((a, b) => b.Value - a.Value); //对统计数据排序 for (int k = ; k < _sortedList.Count; k++)
{
KeyValuePair<string, int> keyValuePair = _sortedList[k];
int index = _posArr[k]; ActiveFunItem funItem = _list[index];
funItem.ItemWidth = _widthArr[k];
funItem.Margin = new Thickness(funItem.OriginalMargin.Left - funItem.ItemWidthHalf, funItem.OriginalMargin.Top - funItem.ItemWidthHalf, , );
funItem.Count = keyValuePair.Value;
funItem.FunName = keyValuePair.Key;
if (_dictNameIcon.Keys.Contains(keyValuePair.Key))
{
funItem.Image = _dictNameIcon[keyValuePair.Key];
}
else
{
funItem.Image = null;
}
}
#endregion }
#endregion #region INotifyPropertyChanged接口
public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion #region UserControl_Loaded
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
double h = this.ActualHeight - ;
double w = this.ActualHeight - ;
if (h < w)
{
viewbox.Height = h;
viewbox.Width = h;
}
else
{
viewbox.Height = w;
viewbox.Width = w;
}
}
#endregion }
}

WPF实现特殊统计图的更多相关文章

  1. WPF实现统计图(饼图仿LiveCharts)

    WPF开发者QQ群: 340500857  | 微信群 -> 进入公众号主页 加入组织 每日一笑 下班和实习生一起回家,公交站等车,一乞丐把碗推向实习生乞讨.这时,实习生不慌不忙的说了句:&qu ...

  2. WPF实现统计图

    WPF开发者QQ群: 340500857  | 微信群 -> 进入公众号主页 加入组织 前言 有小伙伴提出需要实现统计图. 由于在WPF中没有现成的统计图控件,所以我们自己实现一个. PS:有更 ...

  3. Silverlight/WPF绘制统计图Visifire.dll文件

    官网:http://www.visifire.com/ 一直没找到好的中文文档,希望有的这个的可以发个我! 效果图: 前台代码: <UserControl x:Class="Text_ ...

  4. [Aaronyang]谈谈2015年AY对WPF全面技术总结40多篇WPF,炫到没朋友的AYUI来了

             原著:AY WPF博客- 把wpf推广出去,让那些鄙视的人说不 大家好! 我是AY,首先声明,我在做一件很枯燥的事情,我是个91后程序员,每天熬夜完成计划的过着下班后的生活. 那天有 ...

  5. WPF在Canvas中绘图实现折线统计图

    最近在WPF中做一个需要实现统计的功能,其中需要用到统计图,之前也没有接触过,度娘上大多都是各种收费或者免费的第三方控件,不想用第三方控件那就自己画一个吧. 在园子还找到一篇文章,思路来自这篇文章,文 ...

  6. 新手用WPF山寨QQ管家7.6(三)

    由于一直忙工作,没有更新完博客,更可恨的是...在清理资料的时候不小心删除了之前自己做的各种效果的DEMO....好在项目中用到了大部分,也算有所保留,以后可不敢随便删东西了....太可怕了! 在 新 ...

  7. 从头实现一个WPF条形图

    时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...

  8. C# WPF 一个设计界面

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF 一个设计界面 今天正月初三,大家在家呆着挺好,不要忘了自我充电. 武汉人民加油, ...

  9. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

随机推荐

  1. spring 之 BeanPostProcessor

    粗略一看, 它有这么多实现: 可见, 它是多么基础 而重要的一个 接口啊! 它提供了两个方法: public interface BeanPostProcessor { Object postProc ...

  2. laravel表单操作

    $request->all()//获取所有参数if($request->isMethod('GET')){判断是否是GET请求}$res = $request->is('studen ...

  3. leetcode49

    public class Solution { public IList<IList<string>> GroupAnagrams(string[] strs) { var L ...

  4. python 实现统计ftp服务器指定目录下文件夹数目、文件数目及所有文件大小

    本次主要为满足应用方核对上传到ftp服务器的文件是否缺漏. 主要要求:指定目录下,文件夹数目/文件数目/所有文件大小,类似Windows如下功能: 模块介绍: from ftplib import F ...

  5. error: ‘kEmptyString’ is not a member of ‘google::protobuf::internal’

    最近安装caffe,突然报这个错: .build_release/src/caffe/proto/caffe.pb.h: In member function ‘void caffe::ImageDa ...

  6. Rocket MQ 1 - 用

    参考 http://www.iocoder.cn/categories/RocketMQ/ ; https://www.jianshu.com/nb/16219849 首先上启动方法,分别启动name ...

  7. ubuntu16下用QT5实现对话框应用

    ubuntu16下用QT5,实现对话框程序,步骤:生成界面Dialog.ui,将它应用到主程序,通过主程序显示. 一 界面练习 1 Dialog.ui界面生成 在命令行输入:designer 进入界面 ...

  8. jmeter 测试计划

    进行 jmeter 测试时首先都要有一个测试计划,测试计划下的一些名词解释:

  9. 循环TRUNCATE表,再ENABLE约束索引等

    CREATE OR REPLACE PROCEDURE STG.FP_REMOVE_MST_OLD_DATA (EXITCODE OUT NUMBER) IS /******************* ...

  10. Python设计模式 - 基础 - 类/接口之间的六种关系

    在程序中需要把世间万物抽象成相应的类,现实世界中物与物之间的关系和程序中类与类之间的关系相对应,因为世间万物是普遍联系的,所以程序中类与类之间也不是孤立的.在系统分析和框架设计中,根据面向对象机制的三 ...