示例#1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            ActiveCommandCollection ActiveCommands = ctrl.ActiveCommands;

            ActiveCommands.Clear();
            ActiveCommands.Add(CustomControls.ActiveCommand.Ok);
            ActiveCommands.Add(CustomControls.ActiveCommand.Cancel);

            TypeConverter CollectionConverter = TypeDescriptor.GetConverter(ActiveCommands);

            Debug.Assert(CollectionConverter.CanConvertFrom(typeof(string)));
            Debug.Assert(!CollectionConverter.CanConvertFrom(typeof(int)));

            bool IsConvertedFrom;
            bool IsConvertedTo;

            ConvertActiveCommandCollection(CollectionConverter, "Ok", out IsConvertedFrom, ActiveCommands, out IsConvertedTo);
            Debug.Assert(IsConvertedFrom);
            Debug.Assert(IsConvertedTo);

            ConvertActiveCommandCollection(CollectionConverter, 0, out IsConvertedFrom, ActiveCommands, out IsConvertedTo);
            Debug.Assert(!IsConvertedFrom);
            Debug.Assert(!IsConvertedTo);

            TypeConverter Converter = TypeDescriptor.GetConverter(ActiveCommands[0]);

            Debug.Assert(Converter.CanConvertFrom(typeof(string)));
            Debug.Assert(!Converter.CanConvertFrom(typeof(int)));

            ConvertActiveCommand(Converter, "Ok", out IsConvertedFrom, ActiveCommands[0], out IsConvertedTo);
            Debug.Assert(IsConvertedFrom);
            Debug.Assert(IsConvertedTo);

            ConvertActiveCommand(Converter, 0, out IsConvertedFrom, ActiveCommands[0], out IsConvertedTo);
            Debug.Assert(!IsConvertedFrom);
            Debug.Assert(!IsConvertedTo);

            string SystemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
            string User32Path = Path.Combine(SystemPath, "user32.dll");

            DialogValidation.LoadStringFromResourceFile("", 1);
            DialogValidation.LoadStringFromResourceFile(User32Path, 9999);
        }
示例#2
0
        /// <summary>
        ///     Converter from a <see cref="ActiveCommand"/> to the associated content in a <see cref="DialogValidation"/>.
        /// </summary>
        /// <param name="values">The values to convert.</param>
        /// <param name="targetType">This parameter is not used.</param>
        /// <param name="parameter">This parameter is not used.</param>
        /// <param name="culture">This parameter is not used.</param>
        /// <returns>
        ///     A System.Object that represents the converted value
        /// </returns>
        /// <remarks>
        /// <para>The first value must be a <see cref="DialogValidation"/>.</para>
        /// <para>The second value must be a <see cref="ActiveCommand"/>.</para>
        /// </remarks>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Assert.ValidateReference(values);

            if (values.Length > 1 && (values[0] is DialogValidation) && (values[1] is ActiveCommand))
            {
                DialogValidation Control = (DialogValidation)values[0];
                ActiveCommand    Command = (ActiveCommand)values[1];

                if (Command is ActiveCommandOk)
                {
                    return(Control.ContentOk);
                }

                else if (Command is ActiveCommandCancel)
                {
                    return(Control.ContentCancel);
                }

                else if (Command is ActiveCommandAbort)
                {
                    return(Control.ContentAbort);
                }

                else if (Command is ActiveCommandRetry)
                {
                    return(Control.ContentRetry);
                }

                else if (Command is ActiveCommandIgnore)
                {
                    return(Control.ContentIgnore);
                }

                else if (Command is ActiveCommandYes)
                {
                    return(Control.ContentYes);
                }

                else if (Command is ActiveCommandNo)
                {
                    return(Control.ContentNo);
                }

                else if (Command is ActiveCommandClose)
                {
                    return(Control.ContentClose);
                }

                else if (Command is ActiveCommandHelp)
                {
                    return(Control.ContentHelp);
                }

                else if (Command is ActiveCommandTryAgain)
                {
                    return(Control.ContentTryAgain);
                }

                else if (Command is ActiveCommandContinue)
                {
                    return(Control.ContentContinue);
                }
            }

            return(null);
        }