| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- 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
- {
- /// <summary>
- /// PhotoBox.xaml 的交互逻辑
- /// </summary>
- 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));
- ///// <summary>
- ///// 图片地址
- ///// </summary>
- //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;
- //}
- }
- /// <summary>
- /// 是否显示打勾图标
- /// </summary>
- 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;
- }
- /// <summary>
- /// 是否显示打叉图标
- /// </summary>
- 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;
- }
- /// <summary>
- /// 是否显示冻结图标
- /// </summary>
- 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;
- }
- /// <summary>
- /// 是否显示更多图标(此图标可替换图标内容如2PN,4PN,8PN...)
- /// </summary>
- 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;
- }
- /// <summary>
- /// PN图标地址源
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 图标编号
- /// </summary>
- 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();
- }
- /// <summary>
- /// 图片时间
- /// </summary>
- public DateTime CreationTime { get; set; }
- }
- }
|