2009-07-16 105 views
2

我想綁定一個XAML組合框,以便它的列表項是System.IO.Ports.Parity枚舉的成員。wpf綁定組合框枚舉在不同的命名空間

我發現了很多數據綁定枚舉的例子,但是如果枚舉位於不同的命名空間(如System.IO.Ports)中,它似乎不起作用。

現在我有:

<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="parityValues"> 
     <ObjectDataProvider.MethodParameters> 
      <x:Type TypeName="System.IO.Ports.Parity" /> 
     </ObjectDataProvider.MethodParameters> 
    </ObjectDataProvider> 

但我得到的錯誤「類型引用無法找到名爲‘System.IO.Ports.Parity’公共型」。

任何想法如何做到這一點?

回答

4

添加類似

xmlns:sysioports="clr-namespace:System.IO.Ports;assembly=System" 

,然後改變<x:Type />

<x:Type TypeName="sysioports:Parity" /> 

應該使其工作。

+0

我設法弄清除了「sysioports:Parity」部分以外的所有內容。找不到記錄在哪裏...... – Klay 2009-07-16 16:47:54

4

只是因爲你應該包括和使用命名空間這樣

<Window xmlns:custom="clr-namespace:System.IO.Ports.Parity;assembly=SampleLibrary"> 
... 
    <x:Type TypeName="custom:Parity" /> 
... 
</Window> 
+0

謝謝!這完美的作品! – Klay 2009-07-16 16:48:26