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);
}
}
///
/// 显示信息绑定
///
public BindingBase DisplayBinding { get; set; }
///
/// ToopTip绑定
///
public BindingBase ToolTipBinding { get; set; }
///
/// 图片绑定
///
public BindingBase ImageBinding { get; set; }
public static readonly DependencyProperty ItemWidthProperty =
WrapPanel.ItemWidthProperty.AddOwner(typeof(ImageView),new PropertyMetadata(120d));
///
/// 宽
///
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));
///
/// 项目高
///
public double ItemHeight
{
get { return (double)GetValue(ItemHeightProperty); }
set { SetValue(ItemHeightProperty, value); }
}
}
}