private static void BindInternal(string?oldValue, string?newValue, IBinderControllable binder, DependencyObject affectedPart) { _isIn = true; if (oldValue != null) { binder.CleanUp(NamePrefix + oldValue); } if (newValue == null) { return; } var name = NamePrefix + newValue; if (newValue != null && newValue.Contains(':')) { var vals = newValue.Split(new[] { ':' }, 2); newValue = vals[1]; var command = Find(vals[0]); if (command != null) { SetTargetCommand(affectedPart, command); } } else if (GetTargetCommand(affectedPart) == null && newValue != null) { var command = Find(newValue); if (command != null) { SetTargetCommand(affectedPart, command); } } else { var command = GetTargetCommand(affectedPart); if (command is RoutedCommand routedCommand) { name = NamePrefix + routedCommand.Name; } else { name = NamePrefix + command; } } var newlinker = new CommandLinker { CommandTarget = newValue }; binder.Register(name, newlinker, affectedPart); _isIn = false; }
public CommandLinkerTest() { _commandLinker = new CommandLinker(typeof(CommandStubMain).GetTypeInfo().Assembly); }
private static void OnCommandChanged([NotNull] DependencyObject d, DependencyPropertyChangedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(d)) return; _isIn = true; var real = e.NewValue as string; if (real != null && real.Contains(':')) { string[] vals = real.Split(new[] {':'}, 2); real = vals[1]; RoutedCommand command = Find(vals[0]); if (command != null) SetTargetCommand(d, command); } else if (GetTargetCommand(d) == null && real != null) { RoutedCommand command = Find(real); if (command != null) SetTargetCommand(d, command); } foreach (CommandLinker linker in LinkerCollection.Where(linker => Equals(linker.Target, d))) { linker.CommandTarget = real; linker.Bind(); return; } var newlinker = new CommandLinker(d) {CommandTarget = real}; LinkerCollection.Add(newlinker); newlinker.Bind(); _isIn = false; }