c# - Pass Enum value as CommandParameter when the Enum is in the ViewModel -


i still learning wpf binding , have been struggling while. have enum store inside viewmodel so:

namespace thenamespace {     public class frmsetupviewmodel     {         public enum locationlabeltype {location, sample}         ...     } } 

and have button pass 1 of values via commandparameter cannot figure out how work. far, these combinations have tried:

//when value inside frmsetupviewmodel, these not work commandparameter="{x:static local:locationlabeltype.location}" //'type  not found.' commandparameter="{x:static local:frmsetupviewmodel+locationlabeltype.location}" //'type not found.' commandparameter="{x:static local:frmsetupviewmodel.locationlabeltype.location}" //'type not found.'  commandparameter="{binding {x:static local:locationlabeltype.location}}" //'value cannot null' commandparameter="{binding {x:static local:frmsetupviewmodel+locationlabeltype.location}}" //'value cannot null' commandparameter="{binding {x:static local:frmsetupviewmodel.locationlabeltype.location}}" //'value cannot null' 

but if move enum outside vm , name space this:

namespace thenamespace {     public enum locationlabeltype {location, sample}      public class frmsetupviewmodel     {         ...     } } 

this works fine:

//works when enum moved namespace commandparameter="{x:static local:locationlabeltype.location}" 

i assume missing commandparameter?

the vm loaded via datacontext:

<window.datacontext>     <local:frmsetupviewmodel /> </window.datacontext> 

thanks.

this work fine:

commandparameter="{x:static uitest:mainwindow+locationlabeltype.location}" 

you ran project code? wpf designer can show error //'type not found.' if don't build project, because not see type of enum.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -