我正在使用Azure移动服务将数据存储在我的应用程序中。我的一个字段设置为nvarchar(max),并且该字段内的列表将很长。
之前,当我的数据存储在应用程序本身中时,我会将字符串格式化为:
“标题文字\ n•项目\ n•项目\ n•项目\ n标题\ n•项目”
然后,这将跳到遇到的“\ n”的新行。现在,从Azure中提取数据并将其绑定到 TextBlock 时,它不会跳到新行。
我看过是否有 TextBlock 的MultiLine属性,而没有。有什么想法吗?
答案 0 :(得分:0)
如果将AcceptsReturn
XAML控件中的<TextBox>
属性设置为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>
<强> MainPage.xaml.cs中强>:
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; }
}
修改原始帖子后更新。使用<TextBlock>
同样有效。只要文本块的高度设置为多行(在下面的示例中,通过将其绑定到网格单元格),它将正确显示多行,而不需要任何其他属性(如{文本框上的{1}}。如果使用下面的XAML文件替换上面XAML文件中的控制面板网格声明,您将看到多行将显示在文本块上。
AcceptsReturn
答案 1 :(得分:0)
我无法通过应用程序代码完成此操作。相反,我构建了一个从数据库加载数据的简单应用程序。加载数据后,我应用了必要的格式并保存了数据。然后它反映在客户端应用程序中。