One of the usage of nameof
keyword is for setting Binding
in wpf programmatically.
to set Binding
you have to set Path
with string, and with nameof
keyword, it's possible to use Refactor option.
For example, if you have IsEnable
dependency property in your UserControl
and you want to bind it to IsEnable
of some CheckBox
in your UserControl
, you can use these two codes:
CheckBox chk = new CheckBox();
Binding bnd = new Binding ("IsEnable") { Source = this };
chk.SetBinding(IsEnabledProperty, bnd);
and
CheckBox chk = new CheckBox();
Binding bnd = new Binding (nameof (IsEnable)) { Source = this };
chk.SetBinding(IsEnabledProperty, bnd);
It's obvious the first code can't refactor but the secend one...