Ejemplo n.º 1
0
        public override object CreateNewInstance(SelectItem item)
        {
            InArgument argument   = null;
            string     value      = item.Value as string;
            Type       outputType = GetOutputType();

            if (outputType == typeof(object))
            {
                // For Literal<T>, the T can only be value type or string type.
                outputType = typeof(string);
            }
            Debug.Assert(outputType.IsValueType || outputType == typeof(string));

            if (outputType == typeof(string))
            {
                return(CreateNewValueString(value));
            }
            else if (outputType == typeof(DynamicValue))
            {
                return(CreateNewValueDynamic(value));
            }

            MethodInfo method  = this.GetType().GetMethod("CreateNewValue", BindingFlags.NonPublic | BindingFlags.Instance); // NOXLATE
            MethodInfo generic = method.MakeGenericMethod(outputType);

            argument = generic.Invoke(this, new object[] { value }) as InArgument;
            return(argument);
        }
        private void OnHyperlinkClick(object sender, RoutedEventArgs e)
        {
            DependencyObject element = sender as DependencyObject;
            SelectItem       item    = element.GetValue(FrameworkElement.DataContextProperty) as SelectItem;

            Debug.Assert(item != null, "the DataContext should be SelectItem"); //NOXLATE

            SelectContext context = DataContext as SelectContext;

            Debug.Assert(context != null, "the DataContext of the control should derive from SelectContext."); //NOXLATE

            object arg = context.CreateNewInstance(item);

            RaiseEvent(new ItemSelectedEventArgs(ItemSelector.ItemSelectedEvent, this, arg));
        }
        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            e.Handled = true;
            Hyperlink link = sender as Hyperlink;

            Debug.Assert(link != null, "the sender type should be Hyperlink"); //NOXLATE

            SelectItem item = link.DataContext as SelectItem;

            Debug.Assert(item != null, "the DataContext of link type should be SelectItem"); //NOXLATE

            SelectContext context = DataContext as SelectContext;

            Debug.Assert(context != null, "the DataContext of the control should derive from SelectContext."); //NOXLATE

            object arg = context.CreateNewInstance(item);

            if (arg != null)
            {
                RaiseEvent(new ItemSelectedEventArgs(ItemSelector.ItemSelectedEvent, this, arg));
            }
        }
Ejemplo n.º 4
0
 public abstract object CreateNewInstance(SelectItem item);