C# 将Azure中字符串的格式应用于TextBlock

C# 将Azure中字符串的格式应用于TextBlock,c#,azure,windows-phone-8,azure-sql-database,azure-mobile-services,C#,Azure,Windows Phone 8,Azure Sql Database,Azure Mobile Services,我正在使用Azure移动服务在我的应用程序中存储数据。我的一个字段被设置为nvarchar(max),在该字段中将有一个很长的时间列表 以前,当我的数据存储在应用程序中时,我会将字符串格式化为: “标题文本\n•项目\n•项目\n•项目\n•项目\n标题\n•项目” 这将跳到遇到的“\n”上的新行。现在,当从Azure中提取数据并将其绑定到文本块时,它不会跳到新行 我查看了TextBlock是否有多行属性,但没有。有什么想法吗?如果将XAML控件中的AcceptsReturn属性设置为t

我正在使用Azure移动服务在我的应用程序中存储数据。我的一个字段被设置为nvarchar(max),在该字段中将有一个很长的时间列表

以前,当我的数据存储在应用程序中时,我会将字符串格式化为:

“标题文本\n•项目\n•项目\n•项目\n•项目\n标题\n•项目”

这将跳到遇到的“\n”上的新行。现在,当从Azure中提取数据并将其绑定到文本块时,它不会跳到新行


我查看了TextBlock是否有多行属性,但没有。有什么想法吗?

如果将
XAML控件中的
AcceptsReturn
属性设置为true,它将以多行显示文本。下面的示例应用程序正是这样做的:

MainPage.xaml

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
        <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Name="btnStart" Content="Click me"
                Click="btnStart_Click" />
        <TextBox AcceptsReturn="True" Name="txtDebug"
                 Grid.Row="1" />
    </Grid>
</Grid>

我无法通过应用程序代码实现这一点。相反,我构建了一个从数据库加载数据的简单应用程序。加载数据后,我应用了必要的格式并保存了数据。它随后反映在客户端应用程序中。

我的意思是TextBlock而不是TextBox。我仍然无法修复该问题。我已将一个示例项目上载到我的网站。我装订的方式有点不同。再次感谢。还有人有什么想法吗?
public partial class MainPage : PhoneApplicationPage
{
    public static MobileServiceClient MobileService = new MobileServiceClient(
        "https://YOUR-APP-NAME.azure-mobile.net/",
        "YOUR-APPLICATION-KEY"
    );

    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }

    private async void btnStart_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            var table = MobileService.GetTable<Test>();
            var item = new Test
            {
                name = "Header Text \n• Item \n• Item \n• Item \n Header \n• Item"
            };

            await table.InsertAsync(item);
            var inserted = await table.LookupAsync(item.id);
            this.txtDebug.Text = inserted.name;
        }
        catch (Exception ex)
        {
            this.txtDebug.Text = ex.ToString();
        }
    }
}

public class Test
{
    public int id { get; set; }
    public string name { get; set; }
}
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Name="btnStart" Content="Click me"
                Click="btnStart_Click" />
        <TextBlock Text="This will be replaced&#10;after the call to the Mobile Service" Grid.Row="1"
                   Margin="10" Name="txtDebug"/>
        <!--<TextBox AcceptsReturn="True" Name="txtDebug"
                 Grid.Row="1" />-->
    </Grid>