ListBoxItem作为CheckBox

ListBoxItem作为CheckBox

本文介绍了枚举到Wpf ListBoxItem作为CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个枚举,我希望每个枚举项都有一个复选框,
在每个listboxitem(看起来像一张桌子)中

我尝试绘制" ListBox的一行:
("x"代替CheckBox)

--------------------
| X X X(一些文本)|
--------------------

因为只有3个EnumItems我做了硬编码",
对于每个枚举都有一个属性,但是如果我添加一个...:〜

任何对我的提示都会很棒!


Hello there,


I have an enum and i want for every enum item a checkbox,
in every listboxitem (looks like a table)

i try to ''draw'' one line of the ListBox:
(the ''x'' is instead of a CheckBox)

--------------------
|X X X (some text) |
--------------------

Because there are just 3 EnumItems i did it ''hardcoded'',
for every enum a property, but if i add one ... :~

any hints for me would be great!


thanks in advance!

推荐答案


<ListBox Name="listBox" Padding="3" SelectionMode="Extended"

         ItemsSource="{Binding Source={StaticResource ObservablCollectionList}}"

         SelectionChanged="listBox_SelectionChanged" MaxHeight="400">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <!-- TODO: extract enum ! -->
                <CheckBox IsChecked="{Binding ViewChecked}"/>
                <CheckBox IsChecked="{Binding InfoChecked}" />
                <CheckBox IsChecked="{Binding ProdChecked}"/>
                <TextBlock Text="{Binding Text}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>



和枚举:



And the enum:

/// <summary>
/// Mode
/// </summary>
public enum Modi
{
    /// <summary>
    /// View
    /// </summary>
    OhneStempel,
    /// <summary>
    /// Information
    /// </summary>
    InfoDruck,
    /// <summary>
    /// Production
    /// </summary>
    ProduktionsDruck
};




我想要这种样式,但我想说的是绑定到枚举的另一个列表,而不是3个复选框.很难解释您不了解的内容;)
但我希望你能理解我的解释...?

但无论如何,我对ValueConverters并不熟悉.也许这就是解决方案,但是我可以请您向我解释一下吗?

非常感谢!




i want this style, but instead of the 3 Checkboxes i want lets say another list bound to the enum. its hard to explain something you dont understand ;)
but i hope you understand my explanation...?

but anyway im not familiar with ValueConverters. Maybe thats the solution, but may i ask you to explain it with a little snippet to me?

thanks a lot!


这篇关于枚举到Wpf ListBoxItem作为CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:25