gpt4 book ai didi

c# - 从列表框项设置复选框文本值

转载 作者:太空宇宙 更新时间:2023-11-03 13:48:57 26 4
gpt4 key购买 nike

如何为将添加到我的列表框的每个项目绑定(bind)复选框内容值?

<ListBox BorderThickness="2" Height="389" 
HorizontalAlignment="Left" Margin="10,10,0,0"
Name="lboIssues" VerticalAlignment="Top" Width="175"
SelectionMode="Multiple" ItemsSource="{Binding Mode=OneWay}">

然后这是我的 ItemTemplate

<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,5,0,5" Orientation="Horizontal" >
<CheckBox Name="checkbox"
Content="{Binding Path=Value, Mode=OneWay}"
VerticalContentAlignment="Center"
Margin="0,0,5,0"
Width="Auto"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
IsTabStop="False" Checked="FilterCheckbox_CheckChanged"
Unchecked="FilterCheckbox_CheckChanged"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>`

当我检查时,复选框的内容值是空白的。

最佳答案

尝试将其更改为

    <CheckBox   Name="checkbox"
Content="{Binding Path=Value, Mode=OneWay}"
VerticalContentAlignment="Center"
Margin="0,0,5,0"
Width="Auto"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
IsTabStop="False" Checked="FilterCheckbox_CheckChanged"
Unchecked="FilterCheckbox_CheckChanged"
Content="{Binding}"/>

关于c# - 从列表框项设置复选框文本值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14314443/

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