116 lines
3.9 KiB
C#
116 lines
3.9 KiB
C#
using Common.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
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 MegaRobo.C00225155App.MenuViews
|
|
{
|
|
/// <summary>
|
|
/// BottleUserControl.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class LiquidBottleUserControl_Show : UserControl
|
|
{
|
|
public SourceLiquidBottleModel LiquidBottleModel
|
|
{
|
|
get { return (SourceLiquidBottleModel)GetValue(LiquidBottleModelProperty); }
|
|
set { SetValue(LiquidBottleModelProperty, value); }
|
|
}
|
|
|
|
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
|
|
public static readonly DependencyProperty LiquidBottleModelProperty =
|
|
DependencyProperty.Register(
|
|
"LiquidBottleModel",
|
|
typeof(SourceLiquidBottleModel),
|
|
typeof(LiquidBottleUserControl_Show),
|
|
new PropertyMetadata(null, OnLiquidBottleModelChanged)// 重要:默认值设为 null
|
|
);
|
|
|
|
|
|
//public Brush BorderBrushColor
|
|
//{
|
|
// get { return (Brush)GetValue(BorderBrushColorProperty); }
|
|
// set { SetValue(BorderBrushColorProperty, value); }
|
|
//}
|
|
|
|
|
|
//public static readonly DependencyProperty BorderBrushColorProperty =
|
|
// DependencyProperty.Register(
|
|
// "BorderBrushColor",
|
|
// typeof(Brush),
|
|
// typeof(LiquidBottleUserControl),
|
|
// new PropertyMetadata(new SolidColorBrush(Color.FromRgb(66, 66, 66)), OnBorderBrushColorChanged)
|
|
// );
|
|
|
|
|
|
public LiquidBottleUserControl_Show()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private static void OnLiquidBottleModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
var control = (LiquidBottleUserControl_Show)d;
|
|
//if (e.OldValue is SourceLiquidBottleModel oldModel)
|
|
//{
|
|
// oldModel.PropertyChanged -= control.LiquidBottleModel_PropertyChanged;
|
|
//}
|
|
//if (e.NewValue is SourceLiquidBottleModel newModel)
|
|
//{
|
|
// newModel.PropertyChanged += control.LiquidBottleModel_PropertyChanged;
|
|
//}
|
|
control.InvalidateVisual();
|
|
}
|
|
|
|
private void LiquidBottleModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
if (e.PropertyName == nameof(SourceLiquidBottleModel.SourceLiquidName))
|
|
{
|
|
UpdateBorderBrushColor();
|
|
}
|
|
}
|
|
|
|
private void UpdateBorderBrushColor()
|
|
{
|
|
if (LiquidBottleModel != null)
|
|
{
|
|
if (!string.IsNullOrEmpty(LiquidBottleModel.SourceLiquidName))
|
|
{
|
|
LiquidBottleModel.HaveBottle = true;
|
|
}
|
|
else
|
|
{
|
|
LiquidBottleModel.HaveBottle = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Bottle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
//// 创建编辑属性窗口实例
|
|
//var editWindow = new EditLiquidBottlePropertiesWindow
|
|
//{
|
|
// LiquidBottle = this.LiquidBottleModel,
|
|
//};
|
|
|
|
//// 显示编辑属性窗口并等待用户操作
|
|
//if (editWindow.ShowDialog() == true)
|
|
//{
|
|
// // 更新自定义控件的属性
|
|
// this.LiquidBottleModel = editWindow.LiquidBottle;
|
|
//}
|
|
}
|
|
}
|
|
}
|