admin管理员组文章数量:1356097
I am upgrading my app to .NET 9 and previously used this to use commands from my page's vm in a datatemplate for listviews and such:
<ContentPage
...
x:Name="this"
x:DataType="viewmodel:MyViewModel">
...
<DataTemplate x:DataType="model:MyClass">
<Button
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
CommandParameter="{Binding .}" />
...
But now it seems due to the changes to compiled bindings, this no longer works. Does anyone know the new way of doing this? I've looked around online but all the answers are outdated and not specific to .NET 9.
I am upgrading my app to .NET 9 and previously used this to use commands from my page's vm in a datatemplate for listviews and such:
<ContentPage
...
x:Name="this"
x:DataType="viewmodel:MyViewModel">
...
<DataTemplate x:DataType="model:MyClass">
<Button
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
CommandParameter="{Binding .}" />
...
But now it seems due to the changes to compiled bindings, this no longer works. Does anyone know the new way of doing this? I've looked around online but all the answers are outdated and not specific to .NET 9.
Share Improve this question edited Mar 30 at 1:59 Ken White 126k15 gold badges236 silver badges466 bronze badges asked Mar 30 at 1:33 codybchaplincodybchaplin 1991 silver badge10 bronze badges1 Answer
Reset to default 3Well I ended up figuring it out soon after posting this thanks to this thread. I ended up changing:
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
to
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MyViewModel}}, Path=MyCommand, x:DataType=viewmodel:MyViewModel}"
本文标签: mvvmHow to access command from vm from within a datatemplateStack Overflow
版权声明:本文标题:mvvm - How to access command from vm from within a datatemplate? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743999128a2573535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论