当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - mvvm:listview selected item fired when ItemsSource get value

问题描述:

I am new to MVVM I have scenario I have One textbox and One Listview .When textbox text(PONo) changed , the listview get populated with some data (PORecords) by filtering through the text.

My View is:

<TextBox Height="24"

VerticalAlignment="Top"

Width="119"

Text="{Binding Path=PONo,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"

/>

<ListView Height="161"

ItemsSource="{Binding Path=PORecords}"

SelectedItem="{Binding Path=SelectedPO,Mode=TwoWay}"

IsSynchronizedWithCurrentItem="True"

Visibility="{Binding Path=PORecords,Converter={StaticResource ResourceKey=NullToVisibilityConverter}}"

Width="357">

<ListView.View>

<GridView>

<GridViewColumn DisplayMemberBinding="{Binding Path=PurchaseOrderRefNo}"

Header="Order No"

Width="100" />

<GridViewColumn DisplayMemberBinding="{Binding Path=OrderDate, StringFormat=dd-MMM-yyyy}"

Header="Order Date"

Width="100" />

</GridView>

</ListView.View>

</ListView>

My ViewModel is:

 private string _pONo;

public string PONo

{

get { return _pONo; }

set

{

if (value != "" && value!=null)

{

_pONo = value;

List<Tbl_PurchaseOrderMain> _lst = new List<Tbl_PurchaseOrderMain>();

_lst = new Tbl_PurchaseOrderMain().Select(" PurchaseOrderRefNo like '" + _pONo + "%'");

if (_lst.Count != 0)

{

PORecords = _lst;

}

else

{

PORecords = null;

}

}

else

{

PORecords = null;

}

RaisePropertyChanged("PONo");

}

}

private List<Tbl_PurchaseOrderMain> _pORecords;

public List<Tbl_PurchaseOrderMain> PORecords

{

get { return _pORecords; }

set

{

_pORecords = value;

RaisePropertyChanged("PORecords");

}

}

private Tbl_PurchaseOrderMain _selectedPO;

public Tbl_PurchaseOrderMain SelectedPO

{

get { return _selectedPO; }

set

{

_selectedPO = value;

if (SelectedPO != null)

{

PONo = SelectedPO.PurchaseOrderRefNo;

}

else

{

PONo = null;

}

RaisePropertyChanged("SelectedPO");

}

}

My problem is that when I enter text on textbox it will populate the listview (PORecords) with three Items.On that moment the selectedPO property is also fired then the textBox is filled the PONo but my listview then have only one Item the other two item gone .Actually I dont select any item on the Listview.I want to populate the textbox only when I select an Item from the listview whats wrong with my code any body have idea?

分享给朋友:
您可能感兴趣的文章:
随机阅读: