두 개의 열 Devicename 및 DeviceAddress가있는 listview가 있습니다. 나는 listview에 대한 observablecollection을 유지했다. MVVM 패턴을 사용하고 있습니다.ListView ObservableCollection 내의 모든 항목 추가 (WPF Mvvm)
보기 :
<ListView Height="100" ItemsSource="{Binding I2CDeviceList}" SelectedItem="{Binding SelectedI2CAddress, Mode=TwoWay}" Name="I2cDeviceList">
<ListView.View>
<GridView>
<GridViewColumn Header="I2C Device" Width="190" DisplayMemberBinding="{Binding I2CDevName}" />
<GridViewColumn Header="I2C Device Address" Width="203" DisplayMemberBinding="{Binding I2CDeviceAddress}" />
</GridView>
</ListView.View>
</ListView>
두 I2CDevicename 및 I2CDeviceAddress 내 모델 클래스의 일부입니다.
뷰 모델 :
public ObservableCollection<ModelClass> I2CDeviceList
{
get { return _I2CDeviceList; }
set
{
_I2CDeviceList = value;
NotifyPropertyChanged("I2CDeviceList");
}
}
항목은 & DeviceAddress 각각 장치 이름 안에 추가 할 :
{ T("Other"), T("0x00")},
{ T("TI Codec(TLV320AIC3104)"), T("0x18")},
{ T("Chip ID GPIO(PCA9500)"),T("0x20")},
{ T("GPIO - power rail control(PCA9555DB)"),T("0x24")},
{ T("Digital Potentiometer(AD5252)"),T("0x2C")},
{ T("Audience chip(eSxxx)"),T("0x3E")},
{ T("Spartan 3A FPGA(XC3SD3400A)"),T("0x40")},.......
을 지금의 ViewModel 클래스의 생성자에서 나는 OBS 내부의 항목을 추가 할 수 있습니다 .Coll은 다음과 같습니다 :
public ObservableCollection<ModelClass> _I2CDeviceList = new ObservableCollection<ModelClass>()
{
new ModelClass() {I2CDevName = "Other", I2CDeviceAddress= "0x00"},
new ModelClass() {I2CDevName = "TI Codec", I2CDeviceAddress = "0x18"}, .........
};
하지만 15 개의 항목을 추가하는 지루한 작업과 15 개의 항목 진술이 필요합니다. 그들의 말을 피하기 위해 단일 루프를 사용하여 항목을 추가 할 수 있습니까?
먼저, 사용자가 제공 한이 목록을 그게 뭐야? 그 코드인가? – Markus
당신이 내가 목록 안에 추가해야하는 항목을 abt라고 말하면, 나는 그 코드가 아니라고 말해야 만합니다. "기타", "0x00"은 각각 생성자에서 확인할 수있는 devicename과 deviceaddress입니다. –
사실 내가 그런 식으로 코드가 아니라는 것을 이해했습니다. 이미 변수이거나 무언가 였거나 엑셀 시트, 데이터 시트 또는 VS 프로젝트 외부의 것에서 가져온 것 같습니다. – Markus