我的 xaml 文件中有一个列表视图和一个文本框。
看法:
<ListView Grid.Column="0" ItemsSource="{Binding I2CDeviceList}" SelectedItem="{Binding SelectedI2CDeviceList, Mode=TwoWay}" Name="I2cDeviceList" >
<ListView.View>
<GridView>
<GridViewColumn Header="I2C Device" Width="Auto" DisplayMemberBinding="{Binding I2CDevName}" />
<GridViewColumn Header="I2C Device Address" Width="Auto" DisplayMemberBinding="{Binding I2CDeviceAddress}" />
</GridView>
</ListView.View>
</ListView>
<TextBox Height="23" Grid.Column="1" Name="AddressI2C" Text="{Binding Path=AddressMessage, Mode=TwoWay}" />
查看型号:
//List View Property
public ObservableCollection<I2CModel> I2CDeviceList
{
get { return _I2CDeviceList; }
set
{
_I2CDeviceList = value;
NotifyPropertyChanged("I2CDeviceList");
}
}
private I2CModel _selectedI2CDeviceList;
public I2CModel SelectedI2CDeviceList
{
get { return _selectedI2CDeviceList; }
set
{
_selectedI2CDeviceList = value;
AddressMessage = _selectedI2CDeviceList.I2CDeviceAddress; //Displays Address in My textBox
NotifyPropertyChanged("SelectedI2CDevSize");
}
}
// Property for textBox
private string _AddressMessage;
public string AddressMessage
{
get
{
return _AddressMessage;
}
set
{
_AddressMessage = value;
NotifyPropertyChanged("AddressMessage");
}
}
我的要求是,
当我启动应用程序时,是否可以默认选择列表视图的第一项?即,如果我的列表视图中的第一项是“Chip Id”、“0x03”,则在启动时它应该被默认选中,并且地址(0x03)也必须显示在 AddressMessage 文本框中。