ACCESSING SYSTEM ENUMS IN WPF DATATEMPLATES

Alex Leblois

Total Post:67

Points:471
Posted by  Alex Leblois
WPF 
WPF
 4144  View(s)
Ratings:
Rate this:
Hi Developer!

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).

I added this to the 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"

Is it possible to use enums defined in system namespaces, or must you only reference enums defined in your own classes?

Thank you!

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: Accessing system enums in WPF datatemplates

    Hi!

    You can use enum with the {x:Static} form.

    <DataTrigger Binding="{Binding Path=Status}"

                 Value="{x:Static System:ServiceControllerStatus.Running}">

        <Setter TargetName="border" Property="BorderBrush" Value="Green"/>

    </DataTrigger>

    thanks

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!