using System.Linq; using System.Windows; using System.Windows.Controls; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using RecipeEditorLib.RecipeModel.Params; using ExDataGridRow = ExtendedGrid.Microsoft.Windows.Controls.DataGridRow; namespace MECF.Framework.UI.Client.CenterViews.Editors.UserControls { /// /// Interaction logic for RecipeEditor.xaml /// public partial class RecipeEditor : UserControl { public RecipeEditor() { InitializeComponent(); } #region Dependency Properties public static readonly DependencyProperty RecipeProperty = DependencyProperty.Register( nameof(Recipe), typeof(RecipeData), typeof(RecipeEditor), new PropertyMetadata(default(RecipeData))); public RecipeData Recipe { get => (RecipeData)GetValue(RecipeProperty); set => SetValue(RecipeProperty, value); } #endregion #region Events private void DgCustom_OnLoadingRow(object sender, ExtendedGrid.Microsoft.Windows.Controls.DataGridRowEventArgs e) { e.Row.Selected += RowOnSelected; e.Row.Unselected += RowOnUnselected; } private void DgCustom_OnUnloadingRow(object sender, ExtendedGrid.Microsoft.Windows.Controls.DataGridRowEventArgs e) { e.Row.Selected -= RowOnSelected; e.Row.Unselected -= RowOnUnselected; } private void RowOnSelected(object sender, RoutedEventArgs e) { if (!(e.Source is ExDataGridRow dgr)) return; if (!(dgr.DataContext is RecipeStep recipeStep)) return; var param = recipeStep.FirstOrDefault(x => x.Name == RecipColNo.StepNo.ToString()); if (param is StepParam sp) { sp.IsChecked = true; } } private void RowOnUnselected(object sender, RoutedEventArgs e) { if (!(e.Source is ExDataGridRow dgr)) return; if (!(dgr.DataContext is RecipeStep recipeStep)) return; var param = recipeStep.FirstOrDefault(x => x.Name == RecipColNo.StepNo.ToString()); if (param is StepParam sp) { sp.IsChecked = false; } } #endregion } }