WPF绑定失败,当我转到更改elment关于绑定集合的位置时 publicobservableCollection S{get;set;}
S绑定到ListBox控件,开关元素为S,绑定失败。ListBox当前项如下:WPF绑定失败,当我转到更改elment关于绑定集合的位置时 publicobservableCollection S{get;set;},wpf,binding,listbox,wpf-4.0,Wpf,Binding,Listbox,Wpf 4.0,S绑定到ListBox控件,开关元素为S,绑定失败。ListBox当前项如下: 公共字符串CurrentItem { 得到 { 返回m_currentitem; } 设置 { m_currentitem=值; int index=S.IndexOf(值); 如果(索引>=5) { 字符串s=s[4]; S[4]=m_当前项; m_currentitem=s; } } } 有什么方法可以解决问题?谢谢。你想做什么?绑定在哪里失败?我尝试了你的代码,没有例外的问题是去点击LisBox项目,超过5关于
公共字符串CurrentItem
{
得到
{
返回m_currentitem;
}
设置
{
m_currentitem=值;
int index=S.IndexOf(值);
如果(索引>=5)
{
字符串s=s[4];
S[4]=m_当前项;
m_currentitem=s;
}
}
}
有什么方法可以解决问题?谢谢。你想做什么?绑定在哪里失败?我尝试了你的代码,没有例外的问题是去点击LisBox项目,超过5关于索引,切换位置是成功的4。但我去点击相同的项目是失败的切换4。绑定应该是失败的。
public ObservableCollection<string> S { get; set; }
public string CurrentItem
{
get
{
return m_currentitem;
}
set
{
m_currentitem = value;
int index = S.IndexOf(value);
if (index >= 5)
{
string s = S[4];
S[4]= m_currentitem;
m_currentitem = s;
}
}
}
<ListBox ItemsSource="{Binding S}" SelectedItem="{Binding CurrentItem,Mode=TwoWay}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" Loaded="UniformGrid_Loaded"></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>