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】自定义控件之远程图片浏览的更多相关文章

  1. WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目 ...

  2. WPF 图片浏览 伪3D效果

    原文:WPF 图片浏览 伪3D效果 首先上效果图: 因项目要求,需要把图片以"好看"."炫"的效果展示出来,特地研究了一下WPF关于3D方面的制作,奈何最终成果 ...

  3. 【转】WPF自定义控件与样式(12)-缩略图ThumbnailImage /gif动画图/图片列表

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要针对WPF项目 ...

  4. Kinect 开发 —— 图片浏览

    总体思路 首先运用WPF编写一个简单的支持多点触控的图片浏览程序,这方面您可以参看MSDN上的这篇文章,上面有代码,可能需要FQ才能下载.中文的话,您可以参考Gnie同学关于在WPF上面多点触屏(Mu ...

  5. WPF自定义控件与样式(1)-矢量字体图标(iconfont)

    一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...

  6. WPF自定义控件与样式(2)-自定义按钮FButton

    一.前言.效果图 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 还是先看看效果 ...

  7. WPF自定义控件与样式(15)-终结篇 & 系列文章索引 & 源码共享

    系列文章目录  WPF自定义控件与样式(1)-矢量字体图标(iconfont) WPF自定义控件与样式(2)-自定义按钮FButton WPF自定义控件与样式(3)-TextBox & Ric ...

  8. WPF自定义控件与样式(13)-自定义窗体Window & 自适应内容大小消息框MessageBox

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 自定义 ...

  9. WPF自定义控件与样式(14)-轻量MVVM模式实践

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. MVVM是WPF中一个非 ...

随机推荐

  1. 删除docker网络docker0

    yum -y install bridge-utils ifconfig docker0 down brctl delbr docker0

  2. 前端PHP入门-023-重点日期函数之程序执行时间检测

    我们有的时经常需要做程序的执行时间执行效率判断. 实现的思路如下: <?php //记录开始时间 //记录结整时 // 开始时间 减去(-) 结束时间 得到程序的运行时间 ?> 可是大家不 ...

  3. tf.slice函数解析

    tf.slice函数解析 觉得有用的话,欢迎一起讨论相互学习~Follow Me tf.slice(input_, begin, size, name = None) 解释 : 这个函数的作用是从输入 ...

  4. zTree使用技巧与详解

    zTree--Jquery 树插件,是在后台管理页面中常使用到的插件. 使用效果图: 核心代码: zTree配置: var setting = { data:{simpleData:{enable:t ...

  5. DEV GridControl打印 导出

    /// <summary> /// 打印 /// </summary> /// <param name="sender"></param& ...

  6. laravel 模糊查询

    模糊查询: Model::where('field_name','like','%'.$keywords.'%')->get() 转载:http://wenda.golaravel.com/qu ...

  7. 41、用Python实现一个二分查找的函数

    data = [1, 3, 6, 7, 9, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 33, 35] def binary_search(dataset ...

  8. 贪心算法_01背包问题_Java实现

    原文地址:http://blog.csdn.net/ljmingcom304/article/details/50310789 本文出自:[梁敬明的博客] 1.贪心算法 什么是贪心算法?是指在对问题进 ...

  9. 75.VS2013和opencv3.1.0开发环境配置

    首先要做的就是 开发环境配置,具体过程如下: Step 1:OpenCV环境变量配置 我的电脑--->属性--->高级系统设置--->高级--->环境变量--->系统变量 ...

  10. Android快速入门(转自 农民伯伯: http://www.cnblogs.com/over140/)

    前言 这是前段时间用于公司Android入门培训的资料,学习Android三周时间收集整理的,时间仓促,希望能对像我这样还没入门就直接上项目的人一点帮助  :) 声明 欢迎转载,但请保留文章原始出处: ...