你可以做到以下幾點:
在您的XAML:
<toolkit:ListPicker x:Name="DeviceType" ItemSource="{Binding DeviceTypeList}" SelectedItem="{Binding SelectedDeviceType, Mode=TwoWay}"/>
<toolkit:ListPicker x:Name="DeviceName" ItemSource="{Binding DeviceNameList}" />
在您的代碼:
public class ClassName : NotifyChangements
{
private YourType selectedDeviceType;
public YourType SelectedDeviceType
{
get { return selectedDeviceType; }
set
{
selectedDeviceType = value;
NotifyPropertyChanged("SelectedDeviceType");
MAJDeviceName();
}
}
// Later in code.
public void MAJDeviceName()
{
// Add code here that fill the DeviceNameList according to the SelectedDeviceType.
}
}
而對於NotifyChangements類:
using System.ComponentModel;
using System.Runtime.CompilerServices;
public class NotifyChangements : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
public bool NotifyPropertyChanged<T>(ref T variable, T valeur, [CallerMemberName] string property = null)
{
if (object.Equals(variable, valeur)) return false;
variable = valeur;
NotifyPropertyChanged(property);
return (true);
}
}
也必須添加List<YourType> DeviceNameList
作爲一個n屬性,並在該屬性的setter中調用NotifyPropertyChanged("DeviceNameList")
以使其綁定數據。
此外,我會讓你改變變量和輸入名稱,因爲你還沒有提供任何代碼示例!
看看[問]。它有助於如果你有一些示例代碼。 –
綁定兩個連擊是一個非常普遍的任務,並有許多重複。即使WPF的例子也適用,因爲模式仍然完全相同。 – Will