Home > DeveloperSection > Forums > Accessing system enums in WPF datatemplates
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    August-16-2013 5:48 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 3362  View(s)
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!



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    August-17-2013 7:08 AM

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


Don't want to miss updates? Please click the below button!

Follow MindStick