DataTemplate中与TargetNullValue在ListBox [英] DataTemplate with TargetNullValue in a ListBox

查看:150
本文介绍了DataTemplate中与TargetNullValue在ListBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框下面的DataTemplate

I have the following DataTemplate in a Listbox

<ListBox Grid.Column="1" Grid.Row="2" ItemsSource="{Binding People}" SelectedItem="{Binding SelectedPerson}">
<ListBox.ItemTemplate>
	<DataTemplate>
		<TextBlock OverridesDefaultStyle="True"
			   Background="{x:Null}"
			   Margin="0"
			   Padding="0"
			   IsHitTestVisible="True"
			   Text="{Binding TargetNullValue=None}"
		/>
	</DataTemplate>
</ListBox.ItemTemplate>

这完美的作品,在绑定列表中显示无来代替任何空(没有)值。问题是,我不能点击Null值进行选择。选择与键盘完美的作品,只是没有用鼠标。我能做些什么,使列表中的行为Null值,就像任何其他的价值?

This works perfectly, displaying "None" in place of any Null (Nothing) values in the bound list. The problem is that I can't click on the Null values to select them. Selection with the keyboard works perfectly, just not with a mouse. What can I do to make the Null values in the list act just like any other value?

编辑:我还要补充一点,我可以改变文本块的背景,红色,它显示只是像其他人,所以我不认为这是没事点击的情况。我也看着它与史努比,我没有看到在视觉树是一个空项目和正常项目之间不同的属性。

I should also add that I can change the TextBlock's background to Red and it displays just like the others so I don't think it's a case of having nothing to click on. I've also looked at it with Snoop and I don't see any attributes in the visual tree that are different between a Null item and a normal item.

编辑2:我要补充一点,人们实际上是一类重presenting数据库表。它使用ToString方法在默认情况下,显示人民对象。我得到同样的效果,如果我绑定到正确的领域使用的路径选择,我想这将是更容易阅读。

Edit 2: I should add that People is actually a class representing a database table. It uses the ToString method to display the People objects by default. I get the same effect if I bind to the proper field using the Path option and I thought this would be easier to read.

推荐答案

如果你正在寻找一个解决方案,也许你可以找到你想要的这里: <一href="http://stackoverflow.com/questions/518579/why-cant-i-select-a-null-value-in-a-combobox">http://stackoverflow.com/questions/518579/why-cant-i-select-a-null-value-in-a-combobox

If you are looking for a solution, maybe you can find what you want here: http://stackoverflow.com/questions/518579/why-cant-i-select-a-null-value-in-a-combobox

组合框具有相同的行为列表框。

Combobox has the same behavior as ListBox.

这篇关于DataTemplate中与TargetNullValue在ListBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆