Search code examples
c#wpfxamlattached-properties

Convert ComboBox.TextBlock XAML to C#


I have the following fragment of XAML:

<ComboBox
    Name="comboBox1"
    IsEditable="True"
    Text="test"
    TextBlock.TextAlignment="Right" />

How do I convert that to C#? In particular, what does the TextBlock.TextAlignment become?


Solution

  • It's the attached property of TextBlock that you have to use in C# code, commented in code below:

    ComboBox cmb = new ComboBox();
    cmb.Name = "comboBox1";
    cmb.IsEditable = true;
    cmb.Text = "Test";
    TextBlock.SetTextAlignment(cmb, TextAlignment.Right); //here it is