Пример #1
0
        public static void Bind(XamlControl frameworkElement, string eventName, string methodPath, params object[] arguments)
        {
            var eventInfo = frameworkElement.GetType().GetEvent(eventName) ?? throw new MissingFieldException($"Cannot find \"{eventName}\" event");
            var binding   = new EventBinding(methodPath, arguments);
            var handler   = binding.Bind(frameworkElement, eventInfo);

            eventInfo.AddEventHandler(frameworkElement, handler);
        }
Пример #2
0
 public Emitter(TypeBuilder typeBuilder, EventBinding eventBinding, XamlControl source)
 {
     _typeBuilder    = typeBuilder;
     _eventBinding   = eventBinding;
     _source         = source;
     _instanceField  = _typeBuilder.DefineField("_instance", source.GetType(), FieldAttributes.Private);
     _argumentsField = _typeBuilder.DefineField("_arguments", typeof(object[]), FieldAttributes.Private);
     _timerField     = _typeBuilder.DefineField("_timer", typeof(Timer), FieldAttributes.Private);
 }
Пример #3
0
        private EventInfo TryDetermineEventInfo(IServiceProvider serviceProvider, XamlControl frameworkElement)
        {
            var xamlContextField = serviceProvider.GetType().GetField("_xamlContext", BindingFlags.Instance | BindingFlags.NonPublic);

            if (xamlContextField != null)
            {
                var xamlContext        = xamlContextField.GetValue(serviceProvider);
                var parentPropertyProp = xamlContext.GetType().GetProperty("ParentProperty");
                var parentProperty     = parentPropertyProp?.GetValue(xamlContext, null);
                var nameProp           = parentProperty?.GetType().GetProperty("Name");
                if (nameProp != null)
                {
                    var name = nameProp.GetValue(parentProperty, null).ToString();
                    return(frameworkElement.GetType().GetEvent(name));
                }
            }

            return(null);
        }