开发者

WPF: Nested collection binding

开发者 https://www.devze.com 2023-01-16 18:42 出处:网络
My application shows a question and possible answers on that question. Now I want to give the correct answer (specified in the \"CorrectAnswer\" property) a green color. Can someone help me? Thanks.

My application shows a question and possible answers on that question. Now I want to give the correct answer (specified in the "CorrectAnswer" property) a green color. Can someone help me? Thanks.

public class Exercise
{
    public string QuestionText { get; set; }
    public int CorrectAnswer { get; set; }
    public Answer[] Answers { get; set; }
    ...
}

public class Answer
{
    public string AnswerText { get; set; }
    ...
}

XAML:

    <StackPanel Orientation="Vert开发者_运维知识库ical">
        <Label Content="{Binding Path=QuestionText}"></Label>
        <ItemsControl ItemsSource="{Binding Path=Answers}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Label Content="{Binding Path=AnswerText}"></Label>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>


If you have some idea on ValueConverter in WPF, better make use of that. That will give you a lot of flexibility and easy to implement. Please let me know, if you still have some doubt.

0

精彩评论

暂无评论...
验证码 换一张
取 消