6

在互联网上搜索,找不到解决方案。我想我错过了以下代码使文本换行的内容:

<Button x:Name="btnCustomerAging" Background="Green" BorderBrush="Green" Foreground="White" FontSize="33" Horizo​​ntalAlignment="Left" Margin="662,106,0,0" Grid.Row="1" VerticalAlignment="顶部" 高度="213" 宽度="238">

            <文字环绕>  

              客户地点

            </TextWrapping>


</按钮>
4

2 回答 2

7

这将起作用。

<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>
于 2013-09-04T03:03:51.180 回答
1

您可以创建自己的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;
    }
}
于 2014-11-30T06:43:44.047 回答