Binding WPF:嵌套集合绑定
我的应用程序显示了一个问题和该问题的可能答案。现在我想给CorrectAnswer属性中指定的正确答案一个绿色。有人能帮我吗?谢谢Binding WPF:嵌套集合绑定,binding,Binding,我的应用程序显示了一个问题和该问题的可能答案。现在我想给CorrectAnswer属性中指定的正确答案一个绿色。有人能帮我吗?谢谢 public class Exercise { public string QuestionText { get; set; } public int CorrectAnswer { get; set; } public Answer[] Answers { get; set; } ... } public class Answer
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:
如果您对WPF中的ValueConverter有一些想法,最好利用它。这将给您带来很大的灵活性和易于实现。如果您还有疑问,请告诉我。好的,谢谢。我有一个解决办法。我用过多值转换器。
<StackPanel Orientation="Vertical">
<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>