示例#1
0
        private static void AttachDataContext(Control control, object dataContext, RelayInfoCollection collection)
        {
            Type dataType = dataContext.GetType();

            foreach (RelayInfo info in collection)
            {
                PropertyInfo prop = dataType.GetProperty(info.Name);
                if (prop == null)
                {
                    throw new ArgumentNullException($"No property found with the name \"{info.Name}\"!");
                }
                //if (!typeof(ICommand).IsAssignableFrom(prop.PropertyType))
                //	throw new ArgumentNullException($"Property \"{info.Name}\" is not a type of {nameof(ICommand)}!");
                IRelayInfoCommand command = (IRelayInfoCommand)prop.GetValue(dataContext);
                command.Info = info;
                if (command.InputGesture != null)
                {
                    control.InputBindings.Add(new RelayInfoCommandBinding(command));
                }
            }
        }
示例#2
0
 public RelayInfoCommandBinding(IRelayInfoCommand command) : base(command, command.Info.InputGesture)
 {
     Gesture = command.Info.InputGesture;
     Command = command;
 }