c# - 如何显示 LongListSelector 的标题

标签 c# xaml windows-phone-8 windows-phone longlistselector

这是我的 lls:

 <phone:LongListSelector Name="lls" ItemsSource="{Binding Items}">
    <phone:LongListSelector.ListHeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Title}" Foreground="Red"  Margin="0,0,0,10"/>
        </DataTemplate>
    </phone:LongListSelector.ListHeaderTemplate>
    <phone:LongListSelector.ListFooterTemplate>
        <DataTemplate>
            <TextBlock Text="this is a footer"/>
        </DataTemplate>
    </phone:LongListSelector.ListFooterTemplate>
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

和 View 模型:

public class BookViewModel : INotifyPropertyChanged
{
    private string title;
    public string Title
    {
        get
        {
            return title;
        }
        set
        {
            if (value != title)
            {
                title = value;
                NotifyPropertyChanged("Title");
            }
        }
    }

    public ObservableCollection<AuthorViewModel> Items { get; set; }
}

在 navigatedto 中,我获取并分配了页面的 DataContext:

DataContext = book;

但问题是,在 LongListSelector 中没有显示任何标题。在分配 DataContext 之后,我检查了一下,Title 有一个值,但什么也没有出现(项目工作正常并且出现了项目列表)

为什么标题是空的?谢谢。

最佳答案

使用 ListHeader 而不是 ListHeaderTemplate 进行绑定(bind):

<phone:LongListSelector.ListHeader>
    <TextBlock Text="{Binding Title}" Foreground="Red"  Margin="0,0,0,10"/>
</phone:LongListSelector.ListHeader>

关于c# - 如何显示 LongListSelector 的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22214417/

相关文章:

xaml - 如何更改 TFS 2015 XAML 构建代理上的构建超时

c# - 将 View 模型绑定(bind)到 View

c++ - 我是否通过将 Microsoft::WRL::ComPtr 作为引用 (&) 传递来完全否定它的好处?

c# - 客户端服务器身份验证

xaml - 绑定(bind)到 ListView 的 SelectedItem 属性时设置初始选定项

c# - C# 中的 Armadillo 功能

c# - Windows Phone 8 项目中未生成本地化文件

android - InAppBrowser 无法在使用 phonegap 的 Windows Phone 8 中工作

c# - Visual Studio - 以编程方式将调试器附加到远程进程

c# - 您如何将 WCF WSDL 和 XSD 共享给尚未访问该服务的客户端?