Пример #1
0
 /// <summary>
 /// Will create an event handler association for the current element.
 /// </summary>
 /// <remarks>
 /// In contrast to method
 /// <see cref="HandleMemberAssignment"/>,
 /// this method can only be used for the current element, which is part of the
 /// visual tree.
 /// </remarks>
 /// <param name="obj"><see cref="UIElement"/> which defines the event to assign the event
 /// handler specified by <paramref name="value"/> to.</param>
 /// <param name="evt"><see cref="RoutedEvent"/> which is defined on the class of
 /// <paramref name="obj"/>.</param>
 /// <param name="value">Name of the event handler to assign to the specified
 /// event.</param>
 protected void HandleEventAssignment(UIElement obj, RoutedEvent evt, string value)
 {
   if (_getEventHandler == null)
     throw new XamlBindingException("Delegate 'GetEventHandler' is not assigned");
   Delegate dlgt = _getEventHandler(this, evt.HandlerType.GetMethod("Invoke"), value);
   try
   {
     obj.AddHandler(evt, dlgt);
   }
   catch (Exception e)
   {
     throw new XamlBindingException("Error assigning event handler", e);
   }
 }
Пример #2
0
    /// <summary>
    /// Will create an event handler association for the current element, using a command markup extension as handler.
    /// </summary>
    /// <param name="obj"><see cref="UIElement"/> which defines the event to assign the event
    /// handler specified by <paramref name="commandStencil"/> to.</param>
    /// <param name="evt"><see cref="RoutedEvent"/> which is defined on the class of <paramref name="obj"/>.</param>
    /// <param name="commandStencil">Command stencil to be used as event handler.</param>
    protected void HandleEventAssignment(UIElement obj, RoutedEvent evt, ICommandStencil commandStencil)
    {
      try
      {
        // initialize command extension
        var evaluableMarkupExtension = commandStencil as IEvaluableMarkupExtension;
        if (evaluableMarkupExtension != null)
        {
          evaluableMarkupExtension.Initialize(this);
        }

        // add the event handler to the event
        obj.AddHandler(evt, commandStencil);
      }
      catch (Exception e)
      {
        throw new XamlBindingException("Error assigning event handler", e);
      }
    }