WPF Pass current item from list to usercontrol

萝らか妹 提交于 2019-12-04 05:01:14

问题


I am binding to an ObservableCollection<Stage> Stages as the ItemsSource for an ItemsControl:

<ItemsControl ItemsSource="{Binding Path=Stages}">

Is there any way to pass the current stage object to a usercontrol in an item datatemplate like this:

<ItemsControl ItemsSource="{Binding Path=Stages}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:Stage}">
    <local:MyUserControl CustomDependencyProperty="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>

The real problem is I need to have the current Stage object to be a variable in MyUserControl to do some work on it. Passing it to the constructor [like: MyUserControl(Stage s)] seems like a good way of doing it but afaik there is no way to specify that in XAML. Any ideas?

来源:https://stackoverflow.com/questions/3106190/wpf-pass-current-item-from-list-to-usercontrol

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