C# Pivot.HeaderTemplate中的绑定文本
在为自己解决了几个小时的问题后,我完全不知所措,但问题太多了。也许你能帮我:-) 我希望有一个Pivot并将元素绑定到is,因此我编写了一个PivotViewModel类,其中包含一个ObservableCollection(C# Pivot.HeaderTemplate中的绑定文本,c#,xaml,data-binding,windows-phone-7,C#,Xaml,Data Binding,Windows Phone 7,在为自己解决了几个小时的问题后,我完全不知所措,但问题太多了。也许你能帮我:-) 我希望有一个Pivot并将元素绑定到is,因此我编写了一个PivotViewModel类,其中包含一个ObservableCollection(CategoryPageList): 加载应用程序时,我希望看到每个CategoryPage的数据透视项,其中“CategoryName”-属性作为该数据透视项的标题。 使用Expression Blend,我创建了以下XAML代码,但它不起作用,Pivot仍然为空: &l
CategoryPageList
):
加载应用程序时,我希望看到每个CategoryPage的数据透视项,其中“CategoryName”-属性作为该数据透视项的标题。
使用Expression Blend,我创建了以下XAML代码,但它不起作用,Pivot仍然为空:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.DataContext>
<RssReader_ViewModel:PivotViewModel/>
</Grid.DataContext>
<controls:Pivot Title="pivot" ItemsSource="{Binding CategoryPages}">
<controls:Pivot.Resources>
<DataTemplate x:Key="CategoryPivotItemHeaderTemplate">
<TextBlock TextWrapping="Wrap" Text="{Binding CategoryPages[0].CategoryName}"/>
</DataTemplate>
<DataTemplate x:Key="CategoryPivotItemTemplate">
<Grid>
<ListBox/>
</Grid>
</DataTemplate>
</controls:Pivot.Resources>
<controls:Pivot.ItemTemplate>
<StaticResource ResourceKey="CategoryPivotItemTemplate"/>
</controls:Pivot.ItemTemplate>
<controls:Pivot.HeaderTemplate>
<StaticResource ResourceKey="CategoryPivotItemHeaderTemplate"/>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.DataContext>
<RssReader_ViewModel:PivotViewModel/>
</controls:Pivot.DataContext>
</controls:Pivot>
</Grid>
我是一个完全的初学者,没有太多的想法,但我唯一能说的是,XAML中的Text=“{Binding CategoryPages[0].CategoryName}”
看起来很奇怪
有人看见虫子吗?那太好了!
致以最良好的祝愿 尝试删除CategoryPages[0]。尝试删除CategoryPages[0]。尝试在Pivot标记中插入一个空的/dummy
DataContext=“{Binding}”
删除
CategoryPages[0]
,因为您在此没有访问CategoryPages集合的权限。尝试将空的/dummyDataContext=“{Binding}”
插入透视标记
删除
CategoryPages[0]
因为您无法访问此处的CategoryPages集合。您能否发布一个完整的示例,说明您正在尝试执行的操作。我看了一下你做了什么,但是有很多地方我不想去猜。你能举一个完整的例子来说明你在做什么吗。我看了一下你做了些什么,但是有很多地方我不想去猜。
public class CategoryPage : INotifyPropertyChanged
{
private string categoryName;
public CategoryPage(string categoryName)
{
CategoryName = categoryName;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public string CategoryName
{
get { return categoryName; }
set
{
if (categoryName != value)
{
categoryName = value;
NotifyPropertyChanged("CategoryName");
}
}
}
}
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.DataContext>
<RssReader_ViewModel:PivotViewModel/>
</Grid.DataContext>
<controls:Pivot Title="pivot" ItemsSource="{Binding CategoryPages}">
<controls:Pivot.Resources>
<DataTemplate x:Key="CategoryPivotItemHeaderTemplate">
<TextBlock TextWrapping="Wrap" Text="{Binding CategoryPages[0].CategoryName}"/>
</DataTemplate>
<DataTemplate x:Key="CategoryPivotItemTemplate">
<Grid>
<ListBox/>
</Grid>
</DataTemplate>
</controls:Pivot.Resources>
<controls:Pivot.ItemTemplate>
<StaticResource ResourceKey="CategoryPivotItemTemplate"/>
</controls:Pivot.ItemTemplate>
<controls:Pivot.HeaderTemplate>
<StaticResource ResourceKey="CategoryPivotItemHeaderTemplate"/>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.DataContext>
<RssReader_ViewModel:PivotViewModel/>
</controls:Pivot.DataContext>
</controls:Pivot>
</Grid>
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
LayoutRoot.DataContext = App.PivotViewModel;
}
}