简体   繁体   中英

Text wrapping not working when creating Child Element of StackPanel in C#

I am trying to implement a TextBlock in C# which is added to a StackPanel by C# code, I managed to get the TextBlock added but I am not able to make it wrap around text, I have tried the following but it still cuts off text when it's out of length and doesn't wrap it onto a new line.

           sp1.Children.Add(
                 new TextBlock() {
                    Text = longStringNeedingWrap,
                    Width = 590,
                    TextWrapping = Wrap,
                    Height = double.NaN,
                    Margin = new Thickness(10, 3, 10, 0),
            });

I have made sure that I implement the TextWrapping = Wrap by adding public TextWrapping Wrap { get; set; } public TextWrapping Wrap { get; set; } public TextWrapping Wrap { get; set; } , my code shows no errors and runs fine but it still doesn't wrap the text.

Thanks a lot in advance.

Try changing

TextWrapping = Wrap,

to

TextWrapping = TextWrapping.Wrap,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM