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;
您是否尝试从绑定中删除'Mode =“TwoWay'? – XAMeLi
是的,但它也不起作用,也许Microsoft Metro api团队将在未来改进此功能吗? –
”value“如果你在你的转换器中放置了一个断点? – mathieu