Exemplo n.º 1
0
        public Connector(IDataSource dataSource, ICommandSink command)
        {
            _dataSource  = dataSource;
            _commandSink = command;

            _dataSource.DataUpdated += OnDataUpdated;
        }
Exemplo n.º 2
0
        static void OnCommandSinkChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            ICommandSink commandSink = e.NewValue as ICommandSink;

            if (!ConfigureDelayedProcessing(depObj, commandSink))
            {
                ProcessCommandSinkChanged(depObj, commandSink);
            }
        }
Exemplo n.º 3
0
        static void ProcessCommandSinkChanged(DependencyObject depObj, ICommandSink commandSink)
        {
            CommandBindingCollection cmdBindings = GetCommandBindings(depObj);

            if (cmdBindings == null)
            {
                throw new ArgumentException("The CommandSinkBinding.CommandSink attached property was set on an element that does not support CommandBindings.");
            }

            foreach (CommandBinding cmdBinding in cmdBindings)
            {
                CommandSinkBinding csb = cmdBinding as CommandSinkBinding;
                if (csb != null && csb.CommandSink == null)
                {
                    csb.CommandSink = commandSink;
                }
            }
        }
Exemplo n.º 4
0
        // This method is necessary when the CommandSink attached property is set on an element
        // in a template, or any other situation in which the element's CommandBindings have not
        // yet had a chance to be created and added to its CommandBindings collection.
        static bool ConfigureDelayedProcessing(DependencyObject depObj, ICommandSink commandSink)
        {
            bool isDelayed = false;

            CommonElement elem = new CommonElement(depObj);
            if (elem.IsValid && !elem.IsLoaded)
            {
                RoutedEventHandler handler = null;
                handler = delegate
                {
                    elem.Loaded -= handler;
                    ProcessCommandSinkChanged(depObj, commandSink);
                };
                elem.Loaded += handler;
                isDelayed = true;
            }

            return isDelayed;
        }
Exemplo n.º 5
0
        // This method is necessary when the CommandSink attached property is set on an element
        // in a template, or any other situation in which the element's CommandBindings have not
        // yet had a chance to be created and added to its CommandBindings collection.
        static bool ConfigureDelayedProcessing(DependencyObject depObj, ICommandSink commandSink)
        {
            bool isDelayed = false;

            CommonElement elem = new CommonElement(depObj);

            if (elem.IsValid && !elem.IsLoaded)
            {
                RoutedEventHandler handler = null;
                handler = delegate
                {
                    elem.Loaded -= handler;
                    ProcessCommandSinkChanged(depObj, commandSink);
                };
                elem.Loaded += handler;
                isDelayed    = true;
            }

            return(isDelayed);
        }
Exemplo n.º 6
0
 public static void SetCommandSink(DependencyObject obj, ICommandSink value)
 {
     obj.SetValue(CommandSinkProperty, value);
 }
Exemplo n.º 7
0
 public static void SetCommandSink(DependencyObject obj, ICommandSink value)
 {
     obj.SetValue(CommandSinkProperty, value);
 }
Exemplo n.º 8
0
        static void ProcessCommandSinkChanged(DependencyObject depObj, ICommandSink commandSink)
        {
            CommandBindingCollection cmdBindings = GetCommandBindings(depObj);
            if (cmdBindings == null)
                throw new ArgumentException("The CommandSinkBinding.CommandSink attached property was set on an element that does not support CommandBindings.");

            foreach (CommandBinding cmdBinding in cmdBindings)
            {
                CommandSinkBinding csb = cmdBinding as CommandSinkBinding;
                if (csb != null && csb.CommandSink == null)
                    csb.CommandSink = commandSink;
            }
        }
 public WhenConnectingDataSourceAndCommandSink()
 {
     _dataSource  = A.Fake <IDataSource>();
     _commandSink = A.Fake <ICommandSink>();
     _connector   = new Connector(_dataSource, _commandSink);
 }