I have a WPF app. In this app, I have a ComboBox. The ComboBox display a list of algabra formulas. I want my students to be able to choose a formula. The formulas include superscripts. For that reason, I think I need to use a TextBlock like this:
<TextBlock>
<Run>x</Run>
<Run Typography.Variants="Superscript">2</Run>
<Run>+ 2xy </Run>
</TextBlock>
I am putting those formulas in
public class Formula
{
public string Text { get; set; }
public Formula(string text)
{
this.Text = text;
}
}
public class MyViewModel
{
public MyViewModel()
{
this.Formulas = new List<Formula>
{
new Formula("<TextBlock><Run>x</Run><Run Typography.Variants=\"Superscript\">2</Run><Run>+ 2xy </Run></TextBlock>"),
new Formula("<TextBlock><Run>x</Run><Run Typography.Variants=\"Superscript\">3</Run><Run>+ 3xy </Run></TextBlock>")
};
}
}
I am then trying to display those formulas, formatted, as ComboBoxItems. Currently, I have the following:
<ComboBox ItemsSource="{Binding Path=Formulas}" DisplayMemberPath="Text" />
This approach does not show the formulas formatted. Is there a way to bind ComboBoxItems to show formatted values? If so, how?
Thanks!