2012-09-04 41 views
1

我想将我的TextBlock.Text绑定到ListBox.SelectedItems.Count,但我发现当我在列表框中多选项时,我的TextBlock不显示任何内容。绑定到Windows应用商店的SelectedItems.Count

我记得这种方式在WPF中工作,但它不再适用于Windows Store应用程序。

有没有其他解决简单问题的方法?

<StackPanel> 
     <StackPanel.Resources> 
      <local:NumberToTextConverter x:Key="NumToText" /> 
     </StackPanel.Resources> 
     <TextBlock Text="{Binding SelectedItems.Count, ElementName=listBox, Mode=TwoWay, Converter={StaticResource NumToText}}" 
        Height="80" /> 
     <ListBox x:Name="listBox" 
       SelectionMode="Multiple" /> 
    </StackPanel> 

这里是转换器,但在这种情况下没有必要。

internal class NumberToTextConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, string culture) 
    { 
     if(value != null) 
      return ((int)value).ToString(); 

     return null; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, string culture) 
    { 
     throw new NotImplementedException(); 
    } 

} 

我加载一些数据在程序的入口主要。

 List<string> gogoString = new List<string>(); 

     for (int i = 0; i < 4; i++) 
      gogoString.Add(i.ToString()); 

     listBox.ItemsSource = gogoString; 
+2

您是否尝试从绑定中删除'Mode =“TwoWay'? – XAMeLi

+0

是的,但它也不起作用,也许Microsoft Metro api团队将在未来改进此功能吗? –

+0

”value“如果你在你的转换器中放置了一个断点? – mathieu

回答

0

好的,我迟到了,找到答案。

ListBox在WPF中执行INotifyPropertyChanged但在Windows Store应用程序中不执行。这就是为什么我无法在Windows应用商店中从ListBox.Items.CountListBox.SelectedItems.Count收到通知。