123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Media;
- namespace FWindSoft.Wpf.Controls
- {
- public class ImageView : ViewBase
- {
- #region 定义传递依赖参数
- public static readonly DependencyProperty ImageProperty =
- DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ImageView));
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static ImageSource GetImage(DependencyObject dp)
- {
- return dp.GetValue(ImageProperty) as ImageSource;
- }
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static void SetImage(DependencyObject dp, object value)
- {
- dp.SetValue(ImageProperty, value);
- }
- public static readonly DependencyProperty DisplayProperty =
- DependencyProperty.RegisterAttached("Display", typeof(string), typeof(ImageView));
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static string GetDisplay(DependencyObject dp)
- {
- return dp.GetValue(DisplayProperty) as string;
- }
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static void SetDisplay(DependencyObject dp, string value)
- {
- dp.SetValue(DisplayProperty, value);
- }
- public static readonly DependencyProperty ToolTipProperty =
- DependencyProperty.RegisterAttached("ToolTip", typeof(string), typeof(ImageView));
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static string GetToolTip(DependencyObject dp)
- {
- return dp.GetValue(ToolTipProperty) as string;
- }
- [AttachedPropertyBrowsableForType(typeof(ListViewItem))]
- public static void SetToolTip(DependencyObject dp, string value)
- {
- dp.SetValue(ToolTipProperty, value);
- }
- #endregion
- protected override object DefaultStyleKey => new ComponentResourceKey(GetType(), "DefaultStyle");
- protected override object ItemContainerDefaultStyleKey => new ComponentResourceKey(GetType(), "ItemContainerDefaultStyle");
- protected override void PrepareItem(ListViewItem item)
- {
- if(item.DataContext==null)
- {
- item.DataContext = item;
- }
- if (ImageBinding != null)
- {
- item.SetBinding(ImageProperty, ImageBinding);
-
- }
- if (DisplayBinding != null)
- {
- item.SetBinding(DisplayProperty, DisplayBinding);
- }
- if (ToolTipBinding != null)
- {
- item.SetBinding(ToolTipProperty, ToolTipBinding);
- }
- }
- /// <summary>
- /// 显示信息绑定
- /// </summary>
- public BindingBase DisplayBinding { get; set; }
- /// <summary>
- /// ToopTip绑定
- /// </summary>
- public BindingBase ToolTipBinding { get; set; }
- /// <summary>
- /// 图片绑定
- /// </summary>
- public BindingBase ImageBinding { get; set; }
- public static readonly DependencyProperty ItemWidthProperty =
- WrapPanel.ItemWidthProperty.AddOwner(typeof(ImageView),new PropertyMetadata(120d));
- /// <summary>
- /// 宽
- /// </summary>
- public double ItemWidth
- {
- get { return (double)GetValue(ItemWidthProperty); }
- set { SetValue(ItemWidthProperty, value); }
- }
- public static readonly DependencyProperty ItemHeightProperty =
- WrapPanel.ItemHeightProperty.AddOwner(typeof(ImageView), new PropertyMetadata(120d));
- /// <summary>
- /// 项目高
- /// </summary>
- public double ItemHeight
- {
- get { return (double)GetValue(ItemHeightProperty); }
- set { SetValue(ItemHeightProperty, value); }
- }
- }
- }
|