8,736
社区成员
发帖
与我相关
我的任务
分享
<ComboBox SelectedItem="{Binding SelectedData}" ItemsSource="{Binding ComoboxData}"></ComboBox>
<ListView ItemsSource="{Binding GridData}">
<ListView.View>
<GridView>
<GridViewColumn Header="内设机构名称" DisplayMemberBinding="{Binding}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowViewModel();
}
//////////////////
public class MainWindowViewModel : INotifyPropertyChanged
{
private string _SelectedData;
public string SelectedData
{
get { return _SelectedData; }
set
{
_SelectedData = value;
OnPropertyChanged("SelectedData");
}
}
private ObservableCollection<string> _ComoboxSource;
public ObservableCollection<string> ComoboxSource
{
get { return _ComoboxSource; }
set
{
_ComoboxSource = value;
OnPropertyChanged("ComoboxSource");
}
}
private ObservableCollection<string> _GridData;
/// <summary>
/// GridData
/// </summary>
public ObservableCollection<string> GridData
{
get { return _GridData; }
set
{
_GridData = value;
OnPropertyChanged("GridData");
}
}
private void RefreshGridData()
{
GridData.Clear();
//GridData.Add();......
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
可以参照上面的,自己整理下吧,我是简单的写了下,有什么问题,可以再交流~
主要就是MVVM的使用