效果图:

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. orcal 程序自动和手动项

    orcal在电脑开机后,为了可以使用 这两个服务设置为自动(为了使用),其他设置为手动(减少电脑压力):

  2. solr搜索

    安装过程: 原料:solr-4.10.3.tgz.tgz 1.1.1 安装步骤 单独一台虚拟机先全部删除:根目录:rm * -rf             cd /usr/local   \  rm ...

  3. 深度学习原理与框架-递归神经网络-时间序列预测(代码) 1.csv.reader(进行csv文件的读取) 2.X.tolist(将数据转换为列表类型)

    1. csv.reader(csvfile) # 进行csv文件的读取操作 参数说明:csvfile表示已经有with oepn 打开的文件 2. X.tolist() 将数据转换为列表类型 参数说明 ...

  4. Object.defineProperty(o,p,descriptor ) 理解应用

    1. Object.defineProperty  在一个对象上定义一个新属性,或修改一个已经存在的属性, 最终返回这个对象. var __define = this.__define || func ...

  5. 25.Hibernate-配置文件.md

    目录 1.主配置文件 1.1定义 1.1.1分类 1.1.2分类 1.1.3不使用配置文件生成表 1.2教程 2. 映射配置文件 1.主配置文件 1.1定义 1.1.1分类 在hibernate的配置 ...

  6. html2canvas

    最近公司有个需求,实现html 页面元素转为png图像,这边用了html2canvas来实现.,这里记录一下,避免以后忘了~~ 官网链接: http://html2canvas.hertzen.com ...

  7. springmvc shiro UnauthorizedException 异常解决方案

    springMVC 整合 shiro 时,配置了当访问某个URL没有权限时的配置处理: <!-- 通过unauthorizedUrl指定没有权限操作时跳转页面 --><propert ...

  8. idea编辑项目出现【Information:java: javacTask: 源发行版 7 需要目标发行版 1.7】

    在编译项目时候出现问题: Information:java: javacTask: 源发行版 7 需要目标发行版 1.7 解决方案:按着图片操作,这几个地方设置的一样就可以了

  9. 安装fftw到window(vs2010)及使用fftw库函数实现4096点fft变换计算

    Windows下FFTW库的安装: 1. 从网站http://www.fftw.org/install/windows.html上下载最新的预编译文件:    32-bit version: fftw ...

  10. 298. Binary Tree Longest Consecutive Sequence最长连续序列

    [抄题]: Given a binary tree, find the length of the longest consecutive sequence path. The path refers ...