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 Bro.UI.Ctrls { /// /// ProductionSelectionCtrl.xaml 的交互逻辑 /// public partial class ProductionSelectionCtrl : UserControl { #region Property public static readonly DependencyProperty ProductionCodeSourceProperty; public static readonly DependencyProperty CurrentProductionCodeProperty; public static readonly DependencyProperty IsEnableChangeProductionProperty; public List ProductionCodeSource { get => GetValue(ProductionCodeSourceProperty) as List; set => SetValue(ProductionCodeSourceProperty, value); } public string CurrentProductionCode { get => GetValue(CurrentProductionCodeProperty).ToString(); set => SetValue(CurrentProductionCodeProperty, value); } public bool IsEnableChangeProduction { get => (bool)GetValue(IsEnableChangeProductionProperty); set => SetValue(IsEnableChangeProductionProperty, value); } #endregion #region Event //public static RoutedEvent ConfirmProductionChangedEvent; //public event RoutedEventHandler Cmmd_ConfirmProducionChanged //{ // add { AddHandler(ConfirmProductionChangedEvent, value); } // remove { RemoveHandler(ConfirmProductionChangedEvent, value); } //} #endregion public ProductionSelectionCtrl() { InitializeComponent(); } static ProductionSelectionCtrl() { ProductionCodeSourceProperty = DependencyProperty.Register("ProductionCodeSource", typeof(List), typeof(ProductionSelectionCtrl), new PropertyMetadata(new List(), OnProductionCodeSourcePropertyChanged)); CurrentProductionCodeProperty = DependencyProperty.Register("CurrentProductionCode", typeof(string), typeof(ProductionSelectionCtrl), new PropertyMetadata("", OnCurrentProductionCodePropertyChanged)); IsEnableChangeProductionProperty = DependencyProperty.Register("IsEnableChangeProduction", typeof(bool), typeof(ProductionSelectionCtrl), new PropertyMetadata(true, OnIsEnableChangeProductionPropertyChanged)); //ConfirmProductionChangedEvent = EventManager.RegisterRoutedEvent("ConfirmProductionChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ProductionSelectionCtrl)); } private static void OnIsEnableChangeProductionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl; if (ctrl != null) { ctrl.cboPCodes.IsEnabled = ctrl.btnConfirmPCode.IsEnabled = (bool)e.NewValue; } } private static void OnCurrentProductionCodePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl; if (ctrl != null) { ctrl.cboPCodes.SelectedItem = e.NewValue.ToString(); } } private static void OnProductionCodeSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ProductionSelectionCtrl ctrl = d as ProductionSelectionCtrl; if (ctrl != null) { ctrl.cboPCodes.ItemsSource = (e.NewValue as List) ?? new List(); } } private void btnConfirmPCode_Click(object sender, RoutedEventArgs e) { CurrentProductionCode = cboPCodes.SelectedItem.ToString(); } } }