2013-08-16 35 views
1

我想在我自己的類ServiceControllerStatus(在System.ServiceProcess中找到的枚舉)的類中添加名爲'狀態'的屬性的數據觸發器。訪問WPF數據類型中的系統枚舉

我已將此添加到XAML:

xmlns:System="clr-namespace:System.ServiceProcess;assembly=System.ServiceProcess.dll" 

,我試圖用數據觸發基礎上的「狀態」的價值做這個:

<DataTrigger Binding="{Binding Path=Status}" > 
    <DataTrigger.Value>        
     <System:ServiceControllerStatus>Running</System:ServiceControllerStatus> 
    </DataTrigger.Value> 
    <Setter TargetName="border" Property="BorderBrush" Value="Green"/> 
</DataTrigger> 

,但我收到錯誤「 XML名稱空間'clr-namespace:System.ServiceProcess;程序集= System.ServiceProcess.dll'中不存在標記'ServiceControllerStatus'

是否可以使用系統名稱中定義的枚舉p ace,還是隻能引用你自己的類中定義的枚舉?

謝謝!

回答

3

您可以使用枚舉與{x:Static}窗體。

<DataTrigger Binding="{Binding Path=Status}" 
      Value="{x:Static System:ServiceControllerStatus.Running}"> 
    <Setter TargetName="border" Property="BorderBrush" Value="Green"/> 
</DataTrigger> 

UPDATE:

不使用匯編語句.dll擴展名的字符串。

assembly=System.ServiceProcess.dll - >assembly=System.ServiceProcess

xmlns:System="clr-namespace:System.ServiceProcess;assembly=System.ServiceProcess" 

PS:我不擅長英語。

+0

感謝您的迴應,儘管使用您的代碼,我仍然得到相同的錯誤... – Shaun

+0

@Shaun刪除'.dll'。那麼你可以編譯。 – ohyecloudy