gpt4 book ai didi

wpf - 如何通过在 WPF 中绑定(bind)来设置复选框内容的背景颜色

转载 作者:行者123 更新时间:2023-12-04 23:52:36 26 4
gpt4 key购买 nike

我试图弄清楚如何为复选框绑定(bind)内容的背景颜色。这是我的代码,当然背景设置只是改变复选框的颜色而不是文本后面的颜色。

        <ListBox Name="ListBox1" ItemsSource="{Binding Path=relationshipTypesTable.dataTable.DefaultView}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>

<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="True" Content="{Binding typeDesc}" Background="{Binding color}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

最佳答案

试试这个:

<ListBox Name="ListBox1" ItemsSource="{Binding Path=relationshipTypesTable.dataTable.DefaultView}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>

<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="True">
<TextBlock Text="{Binding typeDesc}" Background="{Binding color}"/>
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

关于wpf - 如何通过在 WPF 中绑定(bind)来设置复选框内容的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20478518/

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