c# - Accessing the properties from a known view his viewmodel -
i have view contains usercontrol it's own view & viewmodel.
the usercontrol it's views looks this:
<usercontrol.datacontext> <viewmodel:timepickerviewmodel x:name="timepickerviewmodel"/> </usercontrol.datacontext> in viewmodel of usercontrol have property validtime:
public datetime? validtime { { return validtime; } set { validtime = value; onpropertychanged("validtime"); } } in view contains usercontrol need acces property validtime:
<timepicker:timepickerview grid.row="0" x:name="timepicker"/> <button grid.row="1" content="plan" command="{binding plancommand}" commandparameter=" {binding elementname=timepicker, path=validtime}"/> in viewmodel of last view have this:
public icommand plancommand { { return plancommand ?? new relaycommand<datetime?>(plan); } } void plan(datetime? date) { if(pickedmagnet != null) pickedmagnet.startdateplanned = date; } but datetime? parameter receive in plan method null. in debug mode i've seen property validtime assigned value. tried this:
<button grid.row="1" content="plan" command="{binding plancommand}" commandparameter="{binding elementname=timepicker.timepickerviewmodel, path=validtime}"/> and
<button grid.row="1" content="plan" command="{binding plancommand}" commandparameter="{binding elementname=timepicker, path=timepickerviewmodel.validtime}"/> but none of these works.
anyone knows solution or best practice situation?
after trying fixed way.
commandparameter="{binding elementname=timepicker, path=datacontext.validtime}"
Comments
Post a Comment