gpt4 book ai didi

c# - 从 Avalonia 中的 ItemsControl 按钮绑定(bind)到 MainViewModel 命令

转载 作者:行者123 更新时间:2023-12-02 02:18:17 30 4
gpt4 key购买 nike

我正在尝试从 Avalonia 中的 ItemsControl 按钮创建 ReactiveUI MVVM 绑定(bind)在 WPF 中,这将通过 Freezable BindingProxy 完成。不过,Freezable 似乎在 Avalonia 中不可用。应该如何创建这样的绑定(bind)?

            <ItemsControl Items="{Binding MyQueue}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="My Button"
HorizontalAlignment="Center" VerticalAlignment="Center"
CommandParameter="{Binding}"
Command="{Binding MySpecialCmd}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

引用文献:
https://stackoverflow.com/questions/22073740/binding-visibility-for-datagridcolumn-in-wpf\ https://thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

最佳答案

非常感谢 AvaloniaUI gitter 上的@maxkatz6。解决办法如下:

{Binding $parent[ItemsControl].DataContext.MySpecialCmd}
           <ItemsControl Items="{Binding MyQueue}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="My Button"
HorizontalAlignment="Center" VerticalAlignment="Center"
CommandParameter="{Binding}"
Command="{Binding $parent[ItemsControl].DataContext.MySpecialCmd}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

关于c# - 从 Avalonia 中的 ItemsControl 按钮绑定(bind)到 MainViewModel 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66838386/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com