[英]Accessing system enums in WPF datatemplates
I'm trying to add a data trigger for a property called 'Status' in my own class of type ServiceControllerStatus (an enum found in System.ServiceProcess). 我正在尝试在我自己的ServiceControllerStatus类(在System.ServiceProcess中找到的枚举)类中为名为“Status”的属性添加数据触发器。
I added this to the XAML: 我把它添加到XAML:
xmlns:System="clr-namespace:System.ServiceProcess;assembly=System.ServiceProcess.dll"
And am trying to use data triggers based on the value of 'Status' by doing this: 我正在尝试使用基于“状态”值的数据触发器:
<DataTrigger Binding="{Binding Path=Status}" >
<DataTrigger.Value>
<System:ServiceControllerStatus>Running</System:ServiceControllerStatus>
</DataTrigger.Value>
<Setter TargetName="border" Property="BorderBrush" Value="Green"/>
</DataTrigger>
But am receiving an error "The tag 'ServiceControllerStatus' does not exist in XML namespace 'clr-namespace:System.ServiceProcess;assembly=System.ServiceProcess.dll" 但是收到错误“标签'ServiceControllerStatus'在XML命名空间'clr-namespace中不存在:System.ServiceProcess; assembly = System.ServiceProcess.dll”
Is it possible to use enums defined in system namespaces, or must you only reference enums defined in your own classes? 是否可以使用系统命名空间中定义的枚举,或者您是否只能引用自己类中定义的枚举?
Thank you! 谢谢!
You can use enum with the {x:Static}
form. 您可以使用带有
{x:Static}
表单的枚举。
<DataTrigger Binding="{Binding Path=Status}"
Value="{x:Static System:ServiceControllerStatus.Running}">
<Setter TargetName="border" Property="BorderBrush" Value="Green"/>
</DataTrigger>
UPDATE: 更新:
don't use .dll extension string in assembly statement. 不要在汇编语句中使用.dll扩展名字符串。
assembly=System.ServiceProcess.dll
-> assembly=System.ServiceProcess
assembly=System.ServiceProcess.dll
- > assembly=System.ServiceProcess
xmlns:System="clr-namespace:System.ServiceProcess;assembly=System.ServiceProcess"
PS: I'm not good at English. PS:我不擅长英语。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.