Binding a Property to an Expression

  • When we want to automatically change a value of a "Property" based on an expression we'll use the "BindEvents"
  • By using the "BindEvents" we are "Binding" the value of the "Property" to the code that is set in the "Event"
  • We'll go to the "Events" tab in the "Properties" window, and select the "BindForeColor" event - to dynamically determine the "ForeColor" of our control
  • We can type the name of the method we want, next to the event we wish to bind to

2017 02 24 09H49 01

  • When we click enter, visual studio creates a method for us in the "Code Behind" of our view, where we can write the rules of that we'll determine the value of the property
  • We'll use the Value property of the Event args we get, by writing `e.Value
private void IDontLikeMondays(object sender, ColorBindingEventArgs e)
{
     if (_controller.Orders.OrderDate.DayOfWeek == DayOfWeek.Monday)
         e.Value = Color.Red;
     else
         e.Value = Color.Green;
} 
  • We can use the same method for multiple controls, by selecting these controls while holding the ctrl key, and selecting the method we wrote in the "Properties" window 2017 02 24 09H56 22

  • We can change the way the Active row is displayed on the Grid, by setting it's ActiveRowStyle property: 2017 02 24 09H58 01


Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com