I am still learning WPF Binding and have been struggling with this for a while. I have an enum store inside the ViewModel like so:
namespace theNamespace
{
public class frmSetupViewModel
{
public enum LocationLabelType {Location, Sample}
...
}
}
And I would like have a button pass one of the values via the CommandParameter but cannot figure out how to get it to work. So far, these are the combinations I have tried:
//When value is inside the frmSetupViewModel, these do not work
CommandParameter="{x:Static local:LocationLabelType.Location}" //'Type was not found.'
CommandParameter="{x:Static local:frmSetupViewModel+LocationLabelType.Location}" //'Type was not found.'
CommandParameter="{x:Static local:frmSetupViewModel.LocationLabelType.Location}" //'Type was not found.'
CommandParameter="{Binding {x:Static local:LocationLabelType.Location}}" //'Value cannot be null'
CommandParameter="{Binding {x:Static local:frmSetupViewModel+LocationLabelType.Location}}" //'Value cannot be null'
CommandParameter="{Binding {x:Static local:frmSetupViewModel.LocationLabelType.Location}}" //'Value cannot be null'
But if I move the enum OUTSIDE the VM and into the name space like this:
namespace theNamespace
{
public enum LocationLabelType {Location, Sample}
public class frmSetupViewModel
{
...
}
}
this works just fine:
//Works when enum is moved to Namespace
CommandParameter="{x:Static local:LocationLabelType.Location}"
I assume I am missing something with my CommandParameter?
The VM is loaded via DataContext:
<Window.DataContext>
<local:frmSetupViewModel />
</Window.DataContext>
Thanks.
This work fine:
CommandParameter="{x:Static uiTest:MainWindow+LocationLabelType.Location}"
You ran the project with this code?
WPF designer can show this error //'Type was not found.'
if you don't build the project, because it does not see the type of enum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With