C00225155-02/C00225155/MegaRobo.C00225155/MegaRobo.C00225155App/MenuViews/BottleShow/SampleBottleUserControl_Sho...

114 lines
4.0 KiB
C#
Raw Permalink Normal View History

2026-04-13 09:12:49 +00:00
using Common.Models;
using MegaRobo.C00225155App.MenuViewModels;
using MegaRobo.C00225155App.MenuViews.Bottles;
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;
using System.Windows.Threading;
namespace MegaRobo.C00225155App.MenuViews
{
/// <summary>
/// BottleUserControl.xaml 的交互逻辑
/// </summary>
public partial class SampleBottleUserControl_Show : UserControl
{
//UserControl 的 DataContext 并未设置,而是通过 ReactBottleModel 依赖属性传递数据
public SampleBottleModel SampleBottleModel
{
get { return (SampleBottleModel)GetValue(SampleBottleModelProperty); }
set { SetValue(SampleBottleModelProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SampleBottleModelProperty =
DependencyProperty.Register(
"ReactBottleModel",
typeof(SampleBottleModel),
typeof(SampleBottleUserControl_Show),
//new PropertyMetadata(null, OnReactBottleModelChanged)// 重要:默认值设为 nullKD
new PropertyMetadata(null, OnReactBottleModelChanged)// 重要:默认值设为 nullKD
);
//public Brush BorderBrushColor1
//{
// get { return (Brush)GetValue(BorderBrushColor1Property); }
// set { SetValue(BorderBrushColor1Property, value); }
//}
//public static readonly DependencyProperty BorderBrushColor1Property =
// DependencyProperty.Register(
// "BorderBrushColor1",
// typeof(Brush),
// typeof(LiquidBottleUserControl),
// new PropertyMetadata(new SolidColorBrush(Color.FromRgb(66, 66, 66)))
// );
public SampleBottleUserControl_Show()
{
InitializeComponent();
}
private static void OnReactBottleModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (SampleBottleUserControl_Show)d;
control.InvalidateVisual();//强制重绘
var circleProgress = control.FindName("MyCircleProgress") as CircleProgress; // 需给 CircleProgress 命名
if (circleProgress != null)
{
circleProgress.ForceRefresh();
}
}
//private void ReactBottleModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
//{
// if (e.PropertyName == nameof(ReactBottleModel.HaveBottle))
// {
// UpdateBorderBrushColor();
// }
//}
//private void UpdateBorderBrushColor()
//{
//}
private void Bottle_MouseLeft(object sender, MouseButtonEventArgs e)
{
var viewModel = new EditSampleBottlePropertiesViewModel { SampleBottle = this.SampleBottleModel };
var editWindow = new EditSampleBottlePropertiesWindow { DataContext = viewModel };
// 显示编辑属性窗口并等待用户操作
if (editWindow.ShowDialog() == true)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
viewModel = (EditSampleBottlePropertiesViewModel)editWindow.DataContext;
var circleProgress = this.FindName("MyCircleProgress") as CircleProgress; // 需给 CircleProgress 命名
if (circleProgress != null)
{
circleProgress.ForceRefresh();
}
}));
}
}
}
}