相关疑难解决方法(0)

多个ItemsSource集合绑定

如何将多个不同类型的集合绑定到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)

c# wpf xaml

12
推荐指数
1
解决办法
2万
查看次数

绑定不适用于在 XAML 中创建的 DependencyObject

我尝试使用自定义类在 XAML 中传递多个 CommandParameters。

我创建了一个名为ValueCommandArgs 的类,它继承自DependencyObject并具有两个 DepencyProperties(在本示例中,我们将它们称为Value1Value2)。

应该调用命令并传递该对象的按钮如下所示:

<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 作为参数,但是属性Value1Value2 始终为 null/empty

我知道这可以通过 MultiBinding 和 Converter 来解决,但我认为我尝试的方法将是一种更干净的方法。

为什么这不起作用?

c# wpf xaml binding

5
推荐指数
1
解决办法
1069
查看次数

WPF 向绑定集合添加额外的项目

我有一个ItemsControl绑定物品。正如您在屏幕截图中看到的,这些项目绑定到一个属性,我希望出现一个额外的项目,它的行为与其他项目完全不同。我怎样才能做到这一点(最好只使用 xaml)?

我想要的截图

c# wpf

2
推荐指数
1
解决办法
1698
查看次数

标签 统计

c# ×3

wpf ×3

xaml ×2

binding ×1