0

i want to display a string and three bools in a listbox, therefor i made an ItemTemplate:

    <ListBox x:Name="lstVars" Margin="10,41" Grid.ColumnSpan="4" Grid.Column="1">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <WrapPanel Height="30">
                    <TextBlock  Text="{Binding description}" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200"/>
                    <CheckBox Margin="3" Content="a" IsChecked="{Binding save}" Width="200"/>
                    <CheckBox Margin="3" Content="b" IsChecked="{Binding displayBoard}"  Width="200"/>
                    <CheckBox Margin="3" Content="c" IsChecked="{Binding displayGraph}" Width="200"/>
                </WrapPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

i made a testclass because with my original class it doesnt work (but the same "error" occurs with the testclass):

public class test
{
    public String description;
    public bool save { get; set; }
    public bool displayBoard { get; set; }
    public bool displayGraph { get; set; }

    public test(String description, bool save, bool displayBoard, bool displayGraph)
    {
        this.description = description;
        this.save = save;
        this.displayBoard = displayBoard;
        this.displayGraph = displayGraph;
    }
}

when i add some values to the listbox, the string is not displayed

lstVars.Items.Add(new test("teststring", true, false, true));

listbox

i first thought the text would just be in a not visible row but when i write Text="123test" instead of Text="{Binding description}" it displays 123test like it should.

1 Answer 1

2

You must declare binding objects as properties. Like your bool properties.

public String description {get; set;}
Sign up to request clarification or add additional context in comments.

2 Comments

big thanks to you! i never worked with databinding and i almost knew that i made just a stupid little mistake :-D
It's really little mistake, but causes a lot of headache :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.