如何将多个不同类型的集合绑定到ItemsControl的ItemsSource?
使用单个绑定工作正常:
<ItemsControl ItemsSource="{Binding Foo}" />
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用CompositeCollection时,Foo不显示来自的项目:
<ItemsControl>
<ItemsControl.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Foo}" />
</CompositeCollection>
</ItemsControl.ItemsSource>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud) 我尝试使用自定义类在 XAML 中传递多个 CommandParameters。
我创建了一个名为ValueCommandArgs 的类,它继承自DependencyObject并具有两个 DepencyProperties(在本示例中,我们将它们称为Value1和Value2)。
应该调用命令并传递该对象的按钮如下所示:
<Button Command="{Binding ChangeValueCommand}" Content="Execute Command">
<Button.CommandParameter>
<args:ValueCommandArgs Value1="{Binding TestValue1}" Value2="{Binding TestValue2}" />
</Button.CommandParameter>
</Button>
Run Code Online (Sandbox Code Playgroud)
我确实在命令中获得了一个 ValueCommandArgs-Object 作为参数,但是属性Value1和Value2 始终为 null/empty。
我知道这可以通过 MultiBinding 和 Converter 来解决,但我认为我尝试的方法将是一种更干净的方法。
为什么这不起作用?