private PreviewInvokeEventArgs OnPreviewInvoke()
        {
            var args = new PreviewInvokeEventArgs();
            var h    = this.PreviewInvoke;

            if (h != null)
            {
                h(this, args);
            }

            return(args);
        }
Beispiel #2
0
        private void AssociatedObjectPreviewInvoke(object sender, PreviewInvokeEventArgs e)
        {
            try
            {
                var comparerType    = typeof(Comparer <>).MakeGenericType(this.Lhs.GetType());
                var defaultProperty = comparerType.GetTypeInfo().GetDeclaredProperty("Default");
                var comparer        = (IComparer)defaultProperty.GetValue(null);
                var comparerResult  = comparer.Compare(this.Lhs, System.Convert.ChangeType(this.Rhs, comparerType));
                switch (this.CompareOperator)
                {
                case Op.Eq:
                    e.Cancelling = !(comparerResult == 0);
                    break;

                case Op.Gt:
                    e.Cancelling = !(comparerResult > 0);
                    break;

                case Op.GtEq:
                    e.Cancelling = !(comparerResult >= 0);
                    break;

                case Op.Lt:
                    e.Cancelling = !(comparerResult < 0);
                    break;

                case Op.LtEq:
                    e.Cancelling = !(comparerResult <= 0);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                e.Cancelling = true;
            }
        }