首先,这不是一个绑定或一般问题。该示例在多台机器上正常工作,但只有一台! 我在我的函数中添加了一条线索,这样我可以看到何时调用了属性的集合。 SelectedItem和SelectedIndex都不适用于带Elo触摸屏的Windows 7 Embedded Standard 。 我认为“嵌入”或“触摸屏”是失败的原因。WPF绑定:SelectedItem和SelectedIndex不工作
有没有人有想法?
这里是我的示例代码:
<ListBox ItemsSource="{Binding Source={StaticResource DialogProperties}, Path=ListArticle}"
SelectedIndex="{Binding Source={StaticResource DialogProperties}, Path=ItemIndex, Mode=TwoWay}"
SelectedItem="{Binding Source={StaticResource DialogProperties}, Path=Article, Mode=TwoWay}"
>
这个视图模型:
public IEnumerable<Article> ListArticle { get; private set; }
public Article _Article = null;
public Article Article
{
get { return _Article; }
set {
Trace.WriteLine(String.Format("SetArticle..");
_Article = value;
}
}
public int _ItemIndex = 0;
public int ItemIndex
{
get { return _ItemIndex; }
set {
Trace.WriteLine(String.Format("SetItemIndex");
_ItemIndex = value;
}
}
更新(2015年9月14日): 我添加SelectionChanged事件处理程序列表框,它两台机器都如预期的那样发生火灾。
请注意:我可以很容易地创建一个解决方法来解决这个问题。但是我使用的是“Infragistics WPF框架”,并且无法修复或检查每个事件!
更新(09/16/2015): 所有testet环境都使用最新的.NET Framwork 4.5。
什么是绑定的SelectedIndex,当你已经绑定的SelectedItem的原因是什么? – Clemens
您确定该项目已被选中,而不仅仅是集中? – Wouter
@Clemens:只是为了展示这两个作品。 – Mathias