gpt4 book ai didi

wpf - wpf mvvm中的项目控件

转载 作者:行者123 更新时间:2023-12-03 10:20:05 26 4
gpt4 key购买 nike

我正在使用wpf并使用ItemsControl来表示UI上的类列表。

我的代码是这样的:

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

<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel>
<CheckBox IsChecked="{Binding Path=IsSelected,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,IsAsync=True}"

Margin="2,5"/>
<Button Content="{Binding UsecaseName}"

Margin="2,5"/>
</WrapPanel>
</DataTemplate>

</ItemsControl.ItemTemplate>

</ItemsControl>

现在,我想在列表顶部的两列(全选和UseName)中添加标题。我该怎么做??

最佳答案

以下是解决方案(虽然不是很好的解决方案,但我认为也可以进行更差的设计),请在您的代码中更改bindings:

XAML:

<ItemsControl ItemsSource="{Binding Path=list}" >
<ItemsControl.Template>
<ControlTemplate>
<StackPanel Orientation="Vertical">
<Border BorderThickness="5" BorderBrush="DarkGray">
<StackPanel Orientation="Horizontal">
<Button Content="Select All" Width="80" HorizontalAlignment="Stretch"/>
<Button Content="User name" Width="80" HorizontalAlignment="Stretch"/>
</StackPanel>
</Border>
<Border BorderThickness="5" BorderBrush="LightGray">
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=ItemsSource}">

<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel>
<CheckBox IsChecked="{Binding Path=DeviceState,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,IsAsync=True}"
HorizontalAlignment="Stretch" Width="100" Margin="2,5"/>
<Button Content="{Binding Name}" HorizontalAlignment="Stretch" Width="100" Margin="2,5"/>
</WrapPanel>
</DataTemplate>

</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</StackPanel>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>

输出

list

为什么要将按钮用作标题?您不能只是将按钮放在 ItemsControl之外吗?

关于wpf - wpf mvvm中的项目控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37178561/

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