如何获得绑定控件来报告“空”当它必然是空性的时候?
我正在尝试从此处扩展 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有点巧合的是,我昨晚发布了有关如何扩展 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.
除了 Nigel 的扩展列表框之外,您至少还有几种可能的解决方案:
In addition to Nigel's extended ListBox, you have at least a couple of possible solutions: