Gilad Naaman
Gilad Naaman

Reputation: 6550

Using C# Settings w/ customized class

I'm trying to define a setting w/ a type made by me'self, but I can't seem to find my class in the ComboBox of types in the settings UI (nor in the "Browse" form launched by choosing 'browse' in the ComboBox).

How can I use custom classes inside settings?

My class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Key = System.Windows.Input.Key;

namespace GameOfLife
{
    [Serializable()]
    class KeyShortCut
    {
        [XmlElement("Key")]
        public Key Key { get; private set; }

        [XmlAttribute("Ctrl")]
        public bool Ctrl { get; private set; }

        [XmlAttribute("Alt")]
        public bool Alt { get; private set; }

        [XmlAttribute("Shift")]
        public bool Shift { get; private set; }

        public KeyShortCut(Key Key, bool Ctrl = false, bool Alt = false, bool Shift = false)
        {
            this.Key = Key;

            this.Ctrl = Ctrl;
            this.Alt = Alt;
            this.Shift = Shift;
        }
        public override string ToString()
        {
            StringBuilder str = new StringBuilder(this.Key.ToString());
            if (Ctrl)
                str.Insert(0, "Ctrl + ");
            if (Alt)
                str.Insert(0, "Alt + ");
            if (Shift)
                str.Insert(0, "Shift + ");
            return str.ToString();
        }
    }
}

Upvotes: 1

Views: 404

Answers (1)

Christoph Fink
Christoph Fink

Reputation: 23103

Try to use IXmlSerializable instead of Serializable as it only defines binary serializability or read THIS question/answers.

Upvotes: 2

Related Questions