【发布时间】:2013-09-04 02:54:28
【问题描述】:
在互联网上进行了搜索,找不到解决方案。我想我错过了以下代码以使文本换行:
【问题讨论】:
标签: winrt-xaml
在互联网上进行了搜索,找不到解决方案。我想我错过了以下代码以使文本换行:
【问题讨论】:
标签: winrt-xaml
这会起作用。
<Button x:Name="btnCustomerAging" Background="Green" BorderBrush="Green" Foreground="White" FontSize="33"
HorizontalAlignment="Left" Margin="662,106,0,0" Grid.Row="1" VerticalAlignment="Top" Height="213" Width="238">
<TextBlock Text="Customer Locations" TextWrapping="Wrap" />
</Button>
【讨论】:
您可以创建自己的 WrapButton 并像这样在 XAML 中使用它:
<local:WrapButton x:Name="MyButton" Text="Text that will wrap"/>
这是WrapButton的代码:
public sealed class WrapButton : Button
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(WrapButton), new PropertyMetadata(string.Empty));
public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } }
public WrapButton()
{
var textBlock = new TextBlock { TextAlignment = TextAlignment.Center, TextWrapping = TextWrapping.Wrap };
textBlock.SetBinding(TextBlock.TextProperty, new Binding { Source = this, Path = new PropertyPath("Text") });
Content = textBlock;
}
}
【讨论】: