首页 > 解决方案 > 按钮内的 Xamarin.Forms TextBlock。文本的自定义换行

问题描述

Xamarin.Forms XAML。按钮上的文本错误地移动到新行。我需要这样做,以便我可以配置包装。试图这样做:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="SaleAgent.MainPage"
Title = "Торговый агент">
    <ContentPage.Resources>

        <Style x:Key="buttonStyle" TargetType="{x:Type Button}">
            <Setter Property="FontSize" Value="Small" />

            <Setter Property="Template">
                    <Setter.Value>
                    <TextBlock></TextBlock> 
                    </Setter.Value>
                </Setter>

        </Style>
    </ContentPage.Resources>
    <ContentPage.Content>
        <Grid x:Name="mainGrid" RowSpacing="1" ColumnSpacing="1">
        <Grid.RowDefinitions>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        </Grid.ColumnDefinitions>
            <Button Grid.Row="1" Grid.Column="1" Grid.RowSpan="3" Style="{StaticResource buttonStyle}"/>  
        </Grid>
    </ContentPage.Content>
</ContentPage>

但是 TextBlock 给了我错误:

XLS0414 找不到类型“TextBlock”。确认您没有丢失程序集引用并且所有引用的程序集都已构建

标签: xamlxamarinxamarin.formstextblock

解决方案


您正在使用 WPF/UWP XAML。Xamarin 不支持它。在这里回答它们之间的区别超出了范围,您应该学习它。

但是要回答您的问题(这不是上面代码中的唯一问题),Xamarin 中没有 TextBlock,而是 Label。但这并不能帮助您工作,因为上面使用的完整逻辑是有缺陷的。


推荐阅读