你可以做到以下几点:
在您的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