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.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ivf_tl_Operate.CustomUserControls
{
///
/// PhotoBox.xaml 的交互逻辑
///
public partial class PhotoBox : UserControl
{
public PhotoBox()
{
InitializeComponent();
}
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ImageSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(PhotoBox), new PropertyMetadata(null));
/////
///// 图片地址
/////
//public string ImageSource
//{
// get { return (string)GetValue(ImageSourceProperty); }
// set { SetValue(ImageSourceProperty, value); }
//}
//public static readonly DependencyProperty ImageSourceProperty =
// DependencyProperty.Register("ImageSource", typeof(string), typeof(PhotoBox), new PropertyMetadata("", new PropertyChangedCallback(ImageSourcePropertyChangedCallback)));
private static void ImageSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is string uri)) return;
if (string.IsNullOrEmpty(uri)) return;
//if (uri == "null")
// source._image.Source = null;
//else
//source._image.Source = FileHelper.GetBitmapImage(uri);
//source._image.Source = new BitmapImage(new Uri(uri, UriKind.RelativeOrAbsolute));
//source._image.Source = source.ChangeImage(uri);
/*
source.Dispatcher.BeginInvoke((Action)(() =>
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(uri));
bitmap.EndInit();
bitmap.Freeze();
source._image.Source = bitmap;
source._image.Stretch = Stretch.UniformToFill;
}));*/
//using (var stream = new FileStream(uri, FileMode.Open))
//{
// BitmapImage bitmap = new BitmapImage();
// bitmap.BeginInit();
// bitmap.StreamSource = stream;
// bitmap.CacheOption = BitmapCacheOption.OnLoad;
// bitmap.EndInit();
// bitmap.Freeze();
// if (source._image != null)
// source._image.Source = bitmap;
//}
}
///
/// 是否显示打勾图标
///
public bool IsShowYes
{
get { return (bool)GetValue(IsShowYesProperty); }
set { SetValue(IsShowYesProperty, value); }
}
public static readonly DependencyProperty IsShowYesProperty =
DependencyProperty.Register("IsShowYes", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowYesPropertyChangedCallback)));
private static void IsShowYesPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is bool show)) return;
if (source._imageYes == null) return;
if (show == true)
source._imageYes.Visibility = Visibility.Visible;
else
source._imageYes.Visibility = Visibility.Collapsed;
}
///
/// 是否显示打叉图标
///
public bool IsShowNo
{
get { return (bool)GetValue(IsShowNoProperty); }
set { SetValue(IsShowNoProperty, value); }
}
public static readonly DependencyProperty IsShowNoProperty =
DependencyProperty.Register("IsShowNo", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowNoPropertyChangedCallback)));
private static void IsShowNoPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is bool show)) return;
if (source._imageNo == null) return;
if (show == true)
source._imageNo.Visibility = Visibility.Visible;
else
source._imageNo.Visibility = Visibility.Collapsed;
}
///
/// 是否显示冻结图标
///
public bool IsShowFreezable
{
get { return (bool)GetValue(IsShowFreezableProperty); }
set { SetValue(IsShowFreezableProperty, value); }
}
public static readonly DependencyProperty IsShowFreezableProperty =
DependencyProperty.Register("IsShowFreezable", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowFreezablePropertyChangedCallback)));
private static void IsShowFreezablePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is bool show)) return;
if (source._imageFreezable == null) return;
if (show == true)
source._imageFreezable.Visibility = Visibility.Visible;
else
source._imageFreezable.Visibility = Visibility.Collapsed;
}
///
/// 是否显示更多图标(此图标可替换图标内容如2PN,4PN,8PN...)
///
public bool IsShowMore
{
get { return (bool)GetValue(IsShowMoreProperty); }
set { SetValue(IsShowMoreProperty, value); }
}
public static readonly DependencyProperty IsShowMoreProperty =
DependencyProperty.Register("IsShowMore", typeof(bool), typeof(PhotoBox), new PropertyMetadata(false, new PropertyChangedCallback(IsShowMorePropertyChangedCallback)));
private static void IsShowMorePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is bool show)) return;
if (source._imageMore == null) return;
if (show == true)
source._imageMore.Visibility = Visibility.Visible;
else
source._imageMore.Visibility = Visibility.Collapsed;
}
///
/// PN图标地址源
///
public string MoreImageSource
{
get { return (string)GetValue(MoreImageSourceProperty); }
set { SetValue(MoreImageSourceProperty, value); }
}
public static readonly DependencyProperty MoreImageSourceProperty =
DependencyProperty.Register("MoreImageSource", typeof(string), typeof(PhotoBox), new PropertyMetadata(null, new PropertyChangedCallback(MoreImageSourcePropertyChangedCallback)));
private static void MoreImageSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is string uri)) return;
if (string.IsNullOrEmpty(uri)) return;
if (source._imageMore == null) return;
try
{
source._imageMore.Source = new BitmapImage(new Uri(uri, UriKind.RelativeOrAbsolute));
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 图标编号
///
public long ID
{
get { return (long)GetValue(IDProperty); }
set { SetValue(IDProperty, value); }
}
public static readonly DependencyProperty IDProperty =
DependencyProperty.Register("ID", typeof(long), typeof(PhotoBox), new PropertyMetadata(1L, new PropertyChangedCallback(IDPropertyChangedCallback)));
private static void IDPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (!(e.NewValue is long id)) return;
if (id <= 0) return;
if (source._textId == null) return;
source._textId.Text = id.ToString();
}
public string peiYangShiChang
{
get { return (string)GetValue(peiYangShiChangProperty); }
set { SetValue(peiYangShiChangProperty, value); }
}
// Using a DependencyProperty as the backing store for peiYangShiChang. This enables animation, styling, binding, etc...
public static readonly DependencyProperty peiYangShiChangProperty =
DependencyProperty.Register("peiYangShiChang", typeof(string), typeof(PhotoBox), new PropertyMetadata("0h:0m", new PropertyChangedCallback(peiYangShiChangPropertyChangedCallback)));
private static void peiYangShiChangPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is PhotoBox source)) return;
if (source._textTime == null) return;
source._textTime.Text = e.NewValue.ToString();
}
///
/// 图片时间
///
public DateTime CreationTime { get; set; }
}
}