2011-06-25 63 views
1

我試圖定義一個設置W /由我自己做的類型,但我似乎無法在設置UI中的類型的組合框中找到我的類通過在ComboBox中選擇「瀏覽」啓動的「瀏覽」表單)。使用C#設置W /自定義類

如何在設置中使用自定義類?

我的類:

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(); 
     } 
    } 
} 

回答

2

嘗試使用IXmlSerializable,而不是Serializable因爲它只定義二進制串行化或讀THIS問題/答案。

+0

沒有屬性。雖然同名的接口確實存在。我是否應該實現接口並附加[Serializable]屬性? –

+0

@Gilad:請看我的編輯鏈接,我可能是錯的... – ChrFin

+0

非常感謝:) –