示例#1
0
 /// <summary>
 /// Tries to find the binding notifier matching the event.
 /// </summary>
 /// <param name="eventArgs">The event arguments with the binding name to search for.</param>
 /// <returns>Found notifier, or null if no such element could be found.</returns>
 private HtmlViewBindingViewNotifier FindViewNotifier(HtmlViewBindingNotifiedEventArgs eventArgs)
 {
     foreach (IHtmlViewBinding binding in _bindings)
     {
         HtmlViewBindingViewNotifier viewNotifier = binding.ViewNotifier;
         if ((viewNotifier != null) && viewNotifier.Matches(eventArgs.BindingName, eventArgs.EventType))
         {
             return(viewNotifier);
         }
     }
     return(null);
 }
示例#2
0
        /// <summary>
        /// Creates a generic binding between an HTML element and a viewmodel. This method can
        /// achieve all behaviours the other bind methods can, but is more complex to use.
        /// All parameters are optional and null can be passed.
        /// </summary>
        /// <typeparam name="T">Type of the binding, use "object" if it is unimportant.</typeparam>
        /// <param name="viewSetter">Can write the property to the (HTML) view.</param>
        /// <param name="viewNotifier">Informs about changes/clicks in the (HTML) view.</param>
        /// <param name="viewmodelGetter">Can read the property from the viewmodel.</param>
        /// <param name="viewmodelSetter">Can write the property to the viewmodel.</param>
        /// <param name="viewmodelNotifier">Informs about changes in the viewmodel.</param>
        /// <param name="bindingMode">The binding mode which defines the direction of the binding.</param>
        public void BindGeneric <T>(
            Action <T> viewSetter,
            HtmlViewBindingViewNotifier viewNotifier,
            Func <T> viewmodelGetter,
            Action <T> viewmodelSetter,
            HtmlViewBindingViewmodelNotifier viewmodelNotifier,
            HtmlViewBindingMode bindingMode)
        {
            var binding = new HtmlViewBinding <T>(
                viewSetter, viewNotifier, viewmodelGetter, viewmodelSetter, viewmodelNotifier, bindingMode);

            binding.ValidateBindingModeOrThrow();
            _bindings.Add(binding);
        }
示例#3
0
        /// <summary>
        /// Is triggered when the user started navigating. This is the place we can intercept
        /// the navigation.
        /// </summary>
        /// <param name="sender">The sender of the event or null.</param>
        /// <param name="uri">The navigation Uri.</param>
        private void NavigatingEventHandler(object sender, string uri)
        {
            if (_disposed || string.IsNullOrEmpty(uri) || !uri.Contains(JsNamespace))
            {
                return;
            }

            // Read parameters from requested url
            string queryPart = GetUriQueryPart(uri);
            NameValueCollection queryArguments = HttpUtility.ParseQueryString(queryPart);
            var arguments = new KeyValueList <string, string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (string item in queryArguments)
            {
                arguments[item] = queryArguments[item];
            }

            var eventArgs = new HtmlViewBindingNotifiedEventArgs(arguments[BindingAttribute], arguments[EventTypeAttribute], arguments);

            if (string.IsNullOrEmpty(eventArgs.EventType))
            {
                return;
            }

            HtmlViewBindingViewNotifier notifier = FindViewNotifier(eventArgs);

            if (notifier != null)
            {
                // Matching notifier found, trigger the notifier
                notifier.OnNotified(eventArgs.Parameters);
            }
            else
            {
                // Raise event to let the controller handle the request
                if (UnhandledViewBindingEvent != null)
                {
                    try
                    {
                        UnhandledViewBindingEvent(this, eventArgs);
                    }
                    catch (Exception)
                    {
                        // Todo: We catch the exception because this can freeze the GUI completely. Log it as soon as a log is available.
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HtmlViewBinding{T}"/> class.
        /// </summary>
        /// <param name="viewSetter">Can write the property to the (HTML) view.</param>
        /// <param name="viewNotifier">Informs about changes/clicks in the (HTML) view.</param>
        /// <param name="viewmodelGetter">Can read the property from the viewmodel.</param>
        /// <param name="viewmodelSetter">Can write the property to the viewmodel.</param>
        /// <param name="viewmodelNotifier">Informs about changes in the viewmodel.</param>
        /// <param name="bindingMode">The binding mode which defines the direction of the binding.</param>
        public HtmlViewBinding(
            Action <T> viewSetter,
            HtmlViewBindingViewNotifier viewNotifier,
            Func <T> viewmodelGetter,
            Action <T> viewmodelSetter,
            HtmlViewBindingViewmodelNotifier viewmodelNotifier,
            HtmlViewBindingMode bindingMode)
        {
            _viewSetter       = viewSetter;
            ViewNotifier      = viewNotifier;
            _viewmodelGetter  = viewmodelGetter;
            _viewmodelSetter  = viewmodelSetter;
            BindingMode       = bindingMode;
            ViewmodelNotifier = viewmodelNotifier;

            if (ViewNotifier != null)
            {
                ViewNotifier.Notified += ViewNotifiedEventHandler;
            }
            if (ViewmodelNotifier != null)
            {
                ViewmodelNotifier.Notified += ViewmodelNotifiedEventHandler;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckboxHtmlViewBinding"/> class.
 /// </summary>
 /// <param name="viewSetter">Can write the property to the (HTML) view.</param>
 /// <param name="viewNotifier">Informs about changes/clicks in the (HTML) view.</param>
 /// <param name="viewmodelGetter">Can read the property from the viewmodel.</param>
 /// <param name="viewmodelSetter">Can write the property to the viewmodel.</param>
 /// <param name="viewmodelNotifier">Informs about changes in the viewmodel.</param>
 /// <param name="bindingMode">The binding mode which defines the direction of the binding.</param>
 public CheckboxHtmlViewBinding(Action <bool> viewSetter, HtmlViewBindingViewNotifier viewNotifier, Func <bool> viewmodelGetter, Action <bool> viewmodelSetter, HtmlViewBindingViewmodelNotifier viewmodelNotifier, HtmlViewBindingMode bindingMode)
     : base(viewSetter, viewNotifier, viewmodelGetter, viewmodelSetter, viewmodelNotifier, bindingMode)
 {
 }