MVVM: Binding a ViewModel which takes constructor args to a UserControl

寵の児 提交于 2019-12-01 22:37:15

Assuming that your MainWindows Datacontext is an instance of MainWindowViewModel, you can bind the usercontrol to TvshowGridViewModel like this:

<Window>
... 
<Grid x:Name="LayoutRoot">
    <views:TvshowGridView DataContext={Binding TvshowGridViewModel} x:Name="TheTvshowGridView" Margin="8,8,8,58.96" Grid.Row="1"/>
</Grid>

You also should change the TvshowGridViewModel property code like shown:

public TvshowGridViewModel TvshowGridViewModel 
{ get{return _tvshowGridViewModel;} }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!