效果图:

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. SpringBoot 之jsp

    Boot 内嵌的tomcat 是不支持jsp 的, jetty 也是. 虽然boot也是有默认配置一个InternalResourceViewResolver ,但是它并不像我们在springmvc ...

  2. PHP判断手机、电脑访问

    /*判断用户是手机访问还是电脑访问*/$useragent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/(android|bb\d+|meego). ...

  3. <记录> PHP监控进程状态,完成掉线自动重启

    1. 利用Shell脚本实现 #!/bin/bash PORT= while [ true ];do read -p "please enter the port that you want ...

  4. Delphi中Chrome Chromium、Cef3学习笔记(一)

    原文   http://blog.csdn.net/xtfnpgy/article/details/46635225   官方下载地址:https://cefbuilds.com/ CEF简介: 嵌入 ...

  5. ccc切割刚体

    // http://www.emanueleferonato.com/2011/08/05/slicing-splitting-and-cutting-objects-with-box2d-part- ...

  6. 一次sendmsg的改造过程

    比较蛋疼的一个改造过程,简单记录一下. 场景:用户态使用sendmsg发包,tcp报文,由于内核实现过程中存在一次kernel_read,也就是存在将pagecache中的内容拷贝一次的问题. 为了减 ...

  7. python学习Day3 变量、格式化输出、注释、基本数据类型、运算符

    今天复习内容(7项) 1.语言的分类 -- 机器语言:直接编写0,1指令,直接能被硬件执行 -- 汇编语言:编写助记符(与指令的对应关系),找到对应的指令直接交给硬件执行 -- 高级语言:编写人能识别 ...

  8. ubuntu下搭建svn服务器

    [ubuntu下搭建svn服务器] 1.创建目录 mkdir ~/svn/repository/ 2.创建仓库 svnadmin create repository 3.进入 repository/c ...

  9. 利用travis自动化构建与部署(文档项目)

    背景 保持网站上文档的最新性有比较重要的意义, travis ci 提供了免费的解决方案,本文基于 latex 构建+ aliyun oss 部署对此作了尝试. 项目链接为 https://travi ...

  10. [leetcode]46. Permutations全排列(给定序列无重复元素)

    Given a collection of distinct integers, return all possible permutations. Input: [1,2,3] Output: [ ...