如何获得绑定控件来报告“空”当它必然是空性的时候?

发布于 2024-11-09 12:50:26 字数 1305 浏览 0 评论 0原文

我正在尝试从此处扩展 RSS 阅读器示例。

我已将应用程序转换为全景图。我已经这样做了,以便第一个全景项目加载我的提要,第二个项目具有带有相应复选框的类别。类别通过数据绑定到类别类,该类别从 XML 文件填充。

不管怎样,“我的提要”部分的代码如下所示:

<TextBlock x:Name="ItemName" Text="{Binding ItemTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="ItemDetails" Text="{Binding ItemDetails}" Style="{StaticResource PhoneTextSubtleStyle}"/>

当列表中没有提要时,我试图让它显示“空”(当选中相邻面板中的复选框时,将填充提要) )。因此,我将此代码添加到 MainPage.xaml.cs 中的 OnNavigedTo 方法中,

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    this.DataContext = App.Model;
    base.OnNavigatedTo(e);

    // If there are no feeds yet, let the user know
    if (App.Model.FeedItems.Count == 0)
    {
        App.Model.FeedItems.Add(
                    new ViewModel.ItemModel()
                    {
                        ItemDetails = "",
                        ItemTitle = "Empty!",
                        ItemLink = "#"
                    }
                        );
    }
}

但这不是正确的方法。现在,如果我导航到另一个页面并返回,并且列表中有 feeditems,我仍然会看到“Empty”,后面跟着项目。我该如何解决这个问题?

还有,当“空!”的时候。实际上有效,我仍然可以单击链接(上面的 ItemLink);对于这种情况,如何禁用点击事件?

I'm trying to extend the RSS reader example from here.

I've converted the app to panorama. I've made it so that the first panorama item loads with my feeds, and the second item has categories with corresponding checkboxes. The categories are databound to a Categories class, which gets populated from an XML file.

Anyway, the 'my feeds' section which has code that looks like this:

<TextBlock x:Name="ItemName" Text="{Binding ItemTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="ItemDetails" Text="{Binding ItemDetails}" Style="{StaticResource PhoneTextSubtleStyle}"/>

and I'm trying to get it to display "Empty" when there are no feeds in the list (feeds are populated when the checkboxes in the adjacent panel are checked). So I added this code to my OnNavigatedTo method in MainPage.xaml.cs

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    this.DataContext = App.Model;
    base.OnNavigatedTo(e);

    // If there are no feeds yet, let the user know
    if (App.Model.FeedItems.Count == 0)
    {
        App.Model.FeedItems.Add(
                    new ViewModel.ItemModel()
                    {
                        ItemDetails = "",
                        ItemTitle = "Empty!",
                        ItemLink = "#"
                    }
                        );
    }
}

but that wasn't the right approach. Now if I navigate to another page and come back and there were feeditems in the list, I still get "Empty" followed by the items. How do I fix this?

Also, when the "Empty!" actually works, I am still able to click on the link (ItemLink above); how do I disable the click event for this one case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戒ㄋ 2024-11-16 12:50:26

有点巧合的是,我昨晚发布了有关如何扩展 ListBox 控件以拥有空数据模板的文章。它应该很容易扩展到诸如全景或枢轴控件之类的东西。

基本理论是,您有一个带有“无项目文本”的内容控件,并根据列表框是否有项目来控制它和列表框的可见性。

您可以在扩展 WP7 ListBox 中阅读它。

In a bit of a coincidence I posted last night about how to extend the ListBox control to have an empty data template. It should be easily extended to something like Panorama or Pivot controls.

The basic theory is that you have a content control with your "No items text" and control the visibility of it and the ListBox depending on whether the ListBox has items.

You can read it at Extending the WP7 ListBox.

孤檠 2024-11-16 12:50:26

除了 Nigel 的扩展列表框之外,您至少还有几种可能的解决方案:

  • 创建一个 UserControl 嵌入您的 ListBox 以及显示“空”文本的 TextBlock,并使该 UserControl 切换 ListBox 的可见性或 TextBlock,具体取决于提要列表的内容。
  • 将 ListBox 替换为 Silverlight Toolkit 中的 LongListSelector,并设置该 LongListSelector 的 ListHeader 属性以在以下情况下显示“空”文本:提要列表为空。

In addition to Nigel's extended ListBox, you have at least a couple of possible solutions:

  • Create a UserControl embedding your ListBox plus a TextBlock showing the "Empty" text, and make that UserControl toggle the visibility of the ListBox or TextBlock depending on the content of the feeds list.
  • Replace your ListBox with a LongListSelector from the Silverlight Toolkit and set that LongListSelector's ListHeader property to show the "Empty" text when the feeds list is empty.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文