Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">A System.ComponentModel.ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">The System.Globalization.CultureInfo to use as the current culture.</param>
        /// <param name="value">The System.Object to convert.</param>
        /// <returns>
        /// An <see cref="ActiveCommandCollection"/> that represents the converted value.
        /// </returns>
        /// <remarks>
        /// <para>This method will convert a string with format "&lt;commandname&gt;, ..." where &lt;commandname&gt; is the name of one of the supported commands.</para>
        /// </remarks>
        /// <example>
        /// <code>
        /// "OK, Cancel, Yes, No"
        /// </code>
        /// </example>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string AsString;

            if ((AsString = value as string) != null)
            {
                string[] StringList = AsString.Split(',');

                ActiveCommandCollection Result = new ActiveCommandCollection();
                foreach (string Name in StringList)
                {
                    ActiveCommand Command;
                    if (ActiveCommandTypeConverter.TryParseName(Name.Trim(), out Command))
                    {
                        Result.Add(Command);
                    }
                }

                return(Result);
            }

            return(base.ConvertFrom(context, culture, value));
        }