private static void ParameterChange(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { if (_Mapping == null) { _Mapping = new Dictionary <UIElement, RoutedViewResult>(); } if (d is UIElement) { if (e.NewValue is RoutedViewResult) { RoutedViewResult routeitem = (RoutedViewResult)e.NewValue; if (routeitem.SourceInstance == null) { routeitem.SourceInstance = d; } if (!_Mapping.ContainsKey((UIElement)routeitem.SourceInstance)) { _Mapping.Add((UIElement)routeitem.SourceInstance, routeitem); } } var cmdp = ((UIElement)d).GetType().GetProperty("CommandParameter"); if (cmdp == null) { cmdp.SetValue(d, e.NewValue); } //var p = ((UIElement)d).GetType().GetProperty("CommandParameter"); //if (p != null) //{ // if (e.OldValue != null) // { // p.SetValue(d, null); // } // if (e.NewValue != null) // { // p.SetValue(d, e.NewValue); // } // return; //} } } catch { } }
public RelayCommand() : this((x) => { try { if (x is RoutedViewResult) { RoutedViewResult result = (RoutedViewResult)x; Type modeltype = x.GetType(); var results = result.RoutedValues.Where(w => w.Value.GetType() == modeltype).Select(s => s.Key).ToList(); foreach (var item in results) { if (result.RoutedValues[item] is IBaseViewModel) { IBaseViewModel collection = ((IBaseViewModel)result.RoutedValues[item]); if (collection != null) { collection.ReplyCommand.Execute(x); } } else { var reply = result.RoutedValues[item].GetType().GetProperties().OfType <RelayCommand>(); if (reply.Any()) { reply.Single().Execute(x); } else { result.RoutedValues[item] = x; } } } } } catch { } }) { }