【WPF】自定义控件之远程图片浏览
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging; namespace WpfCopy.Controls
{
class CacheImageControl : Control
{ public bool IsShare
{
get { return (bool)GetValue(IsSharesShareFileProperty); }
set { SetValue(IsSharesShareFileProperty, value); }
} public static readonly DependencyProperty IsSharesShareFileProperty =
DependencyProperty.Register("IsShare", typeof(bool), typeof(CacheImageControl), new PropertyMetadata(false)); public int ClientId
{
get { return (int)GetValue(ClientIdProperty); }
set { SetValue(ClientIdProperty, value); }
} // Using a DependencyProperty as the backing store for ClientId. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ClientIdProperty =
DependencyProperty.Register("ClientId", typeof(int), typeof(CacheImageControl), new PropertyMetadata(0)); public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
} // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("MyProperty", typeof(ImageSource), typeof(CacheImageControl)); public string ImagePath
{
get { return (string)GetValue(ImagePathProperty); }
set { SetValue(ImagePathProperty, value); }
} // Using a DependencyProperty as the backing store for ImagePath. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImagePathProperty =
DependencyProperty.Register("ImagePath", typeof(string), typeof(CacheImageControl), new PropertyMetadata(null, OnImagePathChanged)); public bool IsFailed
{
get { return (bool)GetValue(IsFailedProperty); }
set { SetValue(IsFailedProperty, value); }
} // Using a DependencyProperty as the backing store for IsFailed. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsFailedProperty =
DependencyProperty.Register("IsFailed", typeof(bool), typeof(CacheImageControl), new PropertyMetadata(false)); public bool IsLoading
{
get { return (bool)GetValue(IsLoadingProperty); }
set { SetValue(IsLoadingProperty, value); }
} // Using a DependencyProperty as the backing store for IsLoading. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsLoadingProperty =
DependencyProperty.Register("IsLoading", typeof(bool), typeof(CacheImageControl), new PropertyMetadata(false)); public bool IsEmpty
{
get { return (bool)GetValue(IsEmptyProperty); }
set { SetValue(IsEmptyProperty, value); }
} // Using a DependencyProperty as the backing store for IsEmpty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsEmptyProperty =
DependencyProperty.Register("IsEmpty", typeof(bool), typeof(CacheImageControl), new PropertyMetadata(true)); public static readonly RoutedEvent ImagePathChangedEvent = EventManager.RegisterRoutedEvent("ImagePathChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CacheImageControl)); public event RoutedEventHandler ImagePathChanged
{
add { AddHandler(ImagePathChangedEvent, value); }
remove { RemoveHandler(ImagePathChangedEvent, value); }
} static CacheImageControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CacheImageControl), new FrameworkPropertyMetadata(typeof(CacheImageControl)));
} public static void OnImagePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var sender = d as CacheImageControl;
if (sender != null)
{
var oldValue = e.OldValue as string;
var newValue = e.NewValue as string;
sender.OnImagePathChanged(oldValue, newValue);
}
} protected virtual void OnImagePathChanged(string oldValue, string newValue)
{
if (string.Equals(oldValue, newValue)) return; IsLoading = IsEmpty = IsFailed = false; if (string.IsNullOrWhiteSpace(newValue))
{
IsEmpty = true;
}
else
{
IsLoading = true;
//下载远程图片到本地,下载完成后保存到本地并回调Call_Back方法,呈现本地图片
FileCacheMgr.Instance.GetUserFile(newValue, ClientId, CacheFileEventHandler_CallBack);
}
} ///显示下载图片
void CacheFileEventHandler_CallBack(object sender, CacheFileEventArgs e)
{
if (Application.Current == null) return; Application.Current.Dispatcher.BeginInvoke(new Action<CacheFileEventArgs>(E =>
{
IsLoading = false;
if (E.IsFaulted)
{
IsFailed = true;
}
else
{
ImageSource = new BitmapImage(new Uri(Path.GetFullPath(E.CacheFile.LocalFile), UriKind.Absolute));
}
}), e);
} }
}
【WPF】自定义控件之远程图片浏览的更多相关文章
- WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目 ...
- WPF 图片浏览 伪3D效果
原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...
- 【转】WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目 ...
- Kinect 开发 —— 图片浏览
总体思路 首先运用WPF编写一个简单的支持多点触控的图片浏览程序,这方面您可以参看MSDN上的这篇文章,上面有代码,可能需要FQ才能下载.中文的话,您可以参考Gnie同学关于在WPF上面多点触屏(Mu ...
- WPF自定义控件与样式(1)-矢量字体图标(iconfont)
一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...
- WPF自定义控件与样式(2)-自定义按钮FButton
一.前言.效果图 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 还是先看看效果 ...
- WPF自定义控件与样式(15)-终结篇 & 系列文章索引 & 源码共享
系列文章目录 WPF自定义控件与样式(1)-矢量字体图标(iconfont) WPF自定义控件与样式(2)-自定义按钮FButton WPF自定义控件与样式(3)-TextBox & Ric ...
- WPF自定义控件与样式(13)-自定义窗体Window & 自适应内容大小消息框MessageBox
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 自定义 ...
- WPF自定义控件与样式(14)-轻量MVVM模式实践
一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. MVVM是WPF中一个非 ...
随机推荐
- Linux安全之SYN攻击原理及处理
TCP自从1974年被发明出来之后,历经30多年发展,目前成为最重要的互联网基础协议,但TCP协议中也存在一些缺陷. SYN攻击就是利用TCP协议的缺陷,来导致系统服务停止正常的响应. SYN攻击原理 ...
- 阳/阴性预测值Positive/negative Predictive Value(推荐AA)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005269003&am ...
- 转:Unable to execute dex: Multiple dex files define 解决方法
转自:http://blog.csdn.net/mxlxiao7/article/details/8978930 问题发生概述: 程序编译正常,在用Eclipse调试执行时,报错Unable to e ...
- apache源码安装必须依赖的库apr----/etc/ld.so.conf 文件介绍
Apache所依赖的库,封装了各个系统相关的API等.虽然都是Apache开发的,但是现在最新版本的Apache和APR源码是分开的.要编Apache就必须使用APR. /etc/ld.so.conf ...
- JAVA 日期处理工具类 DateUtils
package com.genlot.common.utils; import java.sql.Timestamp;import java.text.ParseException;import ja ...
- Java实现链式存储的二叉树
二叉树的定义: 二叉树(BinaryTree)是n(n≥0)个结点的有限集,它或者是空集(n=0),或者由一个根结点及两棵互不相交的.分别称作这个根的左子树和右子树的二叉树组成. 二叉树的遍历方式主要 ...
- 解决gridview row 左边序列号 显示不完全的技巧
放在主程序 入口处, public Form1() { InitializeComponent(); gridView1.IndicatorWidth = ; //<宽度值>官方推荐常用是 ...
- 支付宝Android接口4.0以上报错Failure calling remote service
很坑爹的问题,4.0一下没问题,完全按照接口文件写的.网上一查,很多人遇到.最好直接在4.2下调试,看看报错问题,然后度娘. 将RSA文件中的加上“BC”后测试通过...NND PKCS8Encode ...
- 基本控件文档-UITableView---iOS-Apple苹果官方文档翻译
//转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3496969.html 技术博客http://www.cnblogs.com/ChenYi ...
- HMM的概述(五个基本元素、两个假设、三个解决的问题)
一.五个基本元素 HMM是个五元组 λ =( S, O , π ,A,B) S:状态值集合,O:观察值集合,π:初始化概率,A:状态转移概率矩阵,B:给定状态下,观察值概率矩阵 二.两个假设 HM ...