Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted

0) You could create a new property in your data item that combines the item text with the enum name, and bind that new property to the listbox item.

1) You could create a custom ListBoxItem template that contains an element for the listbox item text AND the enum name, and bind the two fields to appropriate properties in the bound data item (you may need an IValueConverter object for the enum).
 
Share this answer
 
v2
Comments
[no name] 22-Apr-14 6:01am    
How can i create Ceckboxes from enum i want to create week days ?
Im not sure, if i understand you right, so i post you my xaml:
XML
<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
};



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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900