2011-05-05 78 views
0

我試圖做同樣的事情,因爲它是在這裏完成:綁定一個固定的單選按鈕器isChecked commandparameter

Unable to find enum type for static reference in WPF

但不是枚舉我有一些字符串常量:

namespace MyProject.XYZ 
{ 
    public class MyConstants 
    { 
      public const string AAA = "Type AAA"; 
      public const string BBB = "Type BBB"; 
      public const string CCC = "Type CCC"; 
      ... 
    } 
} 

我有幾個單選按鈕,看起來像這樣:

... 
xmlns:myConstants="clr-namespace:MyProject.XYZ" 
... 


<RadioButton IsChecked="{Binding Path=CurrentSelection, Converter={StaticResource MyConverter}, ConverterParameter={x:Static myConstants:MyConstants 
.AAA}}" /> 
... 

但是,我收到了有關命令參數的錯誤: 'myConstants:MyConstants.AAA'成員無效,因爲它沒有限定類型名稱。

我已經用枚舉完成了它,但它正常工作,但我正在使用的應用程序嚴重依賴於這些常量。

任何想法,不勝感激。

謝謝。

回答

1

這個答案是有點遲,但對於其他人這會是一個有用的解決方案:

定義類這樣的:

<Window.Resources> 
    <local:MyConstants xmlns:local="clr-namespace:MyProject.XYZ" x:Key="MyConstants"/> 
</Window.Resources> 

和結合這樣的:

{Binding Path=CurrentSelection, Converter={StaticResource MyConverter}, ConverterParameter={StaticResource MyConstants}} 
+0

另一個好的答案!謝謝Silvermind。 – asuciu 2012-04-12 17:25:55

+0

歡迎您;) – Silvermind 2012-04-12 18:48:32