开发者

WPF Pass current item from list to usercontrol

开发者 https://www.devze.com 2023-01-04 08:30 出处:网络
I am binding to an ObservableCollection<Stage> Stages as the ItemsSource for an ItemsControl: <ItemsControl ItemsSource=\"{Binding Path=Stages}\">

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

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

I开发者_JAVA技巧s 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消