C# 在数据透视项上正确显示textblock
我很难在数据透视项中显示文本块的外观。我如何使它看起来像您在创建pivot项目时将获得的默认值 谢谢!:) XAMLC# 在数据透视项上正确显示textblock,c#,windows-phone-7,C#,Windows Phone 7,我很难在数据透视项中显示文本块的外观。我如何使它看起来像您在创建pivot项目时将获得的默认值 谢谢!:) XAML 编辑轴的头模板。以下是默认模板: <DataTemplate x:Key="DataTemplate1"> <Grid> <TextBlock TextWrapping="Wrap" Text="{Binding}" d:LayoutOverrides="Width, Height"/>
编辑轴的
头模板。以下是默认模板:
<DataTemplate x:Key="DataTemplate1">
<Grid>
<TextBlock TextWrapping="Wrap" Text="{Binding}" d:LayoutOverrides="Width, Height"/>
</Grid>
</DataTemplate>
像
<controls:Pivot Title="MY APPLICATION" HeaderTemplate="{StaticResource DataTemplate1}">
编辑:如果试图在数据透视项中显示项目,则应使用列表框
将其添加到页面XAML的顶部
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="DataTemplate1">
<Grid>
<TextBlock Margin="0,0,1,0" Text="{Binding}" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
在数据透视项中,添加一个列表框:
<ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource DataTemplate1}">
</ListBox>
然后,更改获取文件名的函数:
private void LoadFromLocalStorage()
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] fileNames = store.GetFileNames();
var files = new ObservableCollection<string>();
foreach (string s in fileNames)
{
files.Add(s);
}
lbFiles.ItemsSource = files;
}
}
private void loadfromloctorage()
{
使用(IsolatedStorageFile store=IsolatedStorageFile.GetUserStoreForApplication())
{
string[]fileNames=store.GetFileNames();
var files=新的ObservableCollection();
foreach(文件名中的字符串s)
{
文件。添加;
}
lbFiles.ItemsSource=文件;
}
}
这里,列表框“ItemSource”设置为文件名列表
如果您不熟悉这一点,您应该阅读一些WP7教程。这是相当基本的
我应该将其放在页面资源或应用程序资源中的何处。应用程序资源是全局的,而页面是特定于给定页面的。例如,打开App.xaml.cs,并将其粘贴到Hmm中,说明在类型“Textblock”中找不到属性“LayoutOverrides”。d:命名空间是表达式混合的一部分。您可以添加该名称空间,但如果不使用expression blend,只需一起删除属性。@RainbowHat名称空间为“xmlns:d=”,您可以将其与其他名称空间一起添加到文件顶部
<ListBox x:Name="lbFiles" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource DataTemplate1}">
</ListBox>
private void LoadFromLocalStorage()
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] fileNames = store.GetFileNames();
var files = new ObservableCollection<string>();
foreach (string s in fileNames)
{
files.Add(s);
}
lbFiles.ItemsSource = files;
}
}