"wpf datatrigger enum binding" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "wpf datatrigger enum binding" answered properly. Developers are finding an appropriate answer about wpf datatrigger enum binding related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like wpf datatrigger enum binding. Enter your desired code related query in the search bar and get every piece of information about C# code related question on wpf datatrigger enum binding.
wpf datatrigger enum binding
//This example assumes enum and classes are in the same namespace
//If yours are not, use using statements and dot notation
//(Based on an answer from https://social.msdn.microsoft.com/Forums/vstudio/en-US/d22a01cc-91d7-4099-9f56-9707d475a7a8/textblock-text-set-based-on-enumeration?forum=wpf )
//Code-behind, C#
public enum EnumVals
{
Excellent,
Poor
}
public partial class MyUserControl : UserControl
{
private MyDataContext myDC;
public MyUserControl()
{
InitializeComponent();
myDC = new MyDataContext();
this.DataContext = myDC;
}
}
//Helper class
public class MyDataContext : DependencyObject
{
public static readonly DependencyProperty CurStateProperty = DependencyProperty.Register("CurState", typeof(EnumVals), typeof(MyDataContext), new UIPropertyMetadata(EnumVals.Excellent));
public EnumVals CurState
{
get => (EnumVals)GetValue(CurStateProperty);
set => SetValue(CurStateProperty, value);
}
}
//XAML file snippet. Using the example of changing the fill of a polygon
//based on the value of the enum
<UserControl.Resources>
<Style TargetType="{x:Type Polygon}">
<Style.Triggers>
<DataTrigger Binding="{Binding CurState}" Value="Excellent">
<Setter Property="Fill" Value="LimeGreen"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=CurState}" Value="Poor">
<Setter Property="Fill" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
Source: social.msdn.microsoft.com
All those coders who are working on the C# based application and are stuck on wpf datatrigger enum binding can get a collection of related answers to their query. Programmers need to enter their query on wpf datatrigger enum binding related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about wpf datatrigger enum binding for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of wpf datatrigger enum binding while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "wpf datatrigger enum binding". Visit this developer's friendly online web community, CodeProZone, and get your queries like wpf datatrigger enum binding resolved professionally and stay updated to the latest C# updates.