wpf - Reference the View from ViewModel while using DataTemplate for the ViewModel -
i'm using datatemplate provide association of view viewmodel, example:
<datatemplate datatype="{x:type viewmodels:someviewmodel}"> <views:someview /> </datatemplate> now need reference view somehow in viewmodel, reference control directly name. there anyway that?
- note tried add someview parameter someviewmodel ctor someview ctor being invoked twice(one instance sent someviewmodel ctor , because of framework guess...)
thanks help
maybe you're looking for:
public partial class someview : usercontrol { public someview() { initializecomponent(); this.loaded += view_loaded; } void someview_loaded(object sender, routedeventargs e) { var someviewmodel = (someviewmodel)this.datacontext; someviewmodel.view = this; } }
Comments
Post a Comment