Code //Xaml写法 //TextWrapping = "Wrap"即可。 //注意:只有当Text内容长度超过TextBox的总长度时才会自动换行,上次听新人(比我还新)说怎么没效果,后来发现他的 //这个Grid.Row="0" Grid.Column="4" 的列宽是Auto属性。 <TextBox Margin="10" HorizontalAlignment="Left" Text="TextBox with a line of text that wraps." FontFamily="Arial" TextWrapping="Wrap" Grid.Row="0" Grid.Column="4"/>
//Cs写法 TextBox txtWarp=new TextBox(); txtWarp.Text ="TextBox with a line of text that wraps."; txtWarp.FontFamily =new FontFamily("Arial"); txtWarp.TextWrapping = TextWrapping.Wrap; txtWarp.Width =100.0; LayoutRoot.Children.Add(txtWarp);