If you are ok with creating and using a custom Grid (having the same properties as a Grid
) instead:
public class CustomGrid: Grid
{
public CustomGrid() : this() { }
public void BindIsVisible(string bindobj, object sourceobj = null) {
SetBinding(Grid.IsVisibleProperty, bindobj)
}
}
var grid3Help = new CustomGrid().BindIsVisible(nameof(HelpIconVisible), source: this)
With extension method:
namespace ExtensionMethods
{
public static class MyExtensions
{
public static void BindIsVisible(this Grid grid, string boundproperty)
{
grid.SetBinding(VisualElement.IsVisibleProperty, boundproperty);
return;
}
}
}
Don't forget to include the namespace: using ExtensionMethods;
In both cases you will have to send the parameter with nameof()
otherwise you can try something a bit complicated Finding the variable name passed to a function