如何在WPF中重新加载(重置)整个页面?

我有Request.xaml按钮和许多comboxes,所以我想重新加载它并将combox值置于按钮点击后将其设置为默认值。 我当然会做更多的工作人员。

我的Request.xaml代码包含以下部分代码:

       

另外,xaml代码这样的事件 // // //ViewModel public class MainViewModel : INotifyPropertyChanged { private IList _items; private bool _canExecute; private ICommand _clickCommand; private string _textValue; private string _selectedValue; public IList Items { get { return _items; } } public string SelectedValue { get { return _selectedValue; } set { _selectedValue = value; OnPropertyChanged("SelectedValue"); } } public string TextValue { get { return _textValue; } set { _textValue = value; OnPropertyChanged("TextValue");} } public void Save() { SelectedValue = _items.FirstOrDefault(); TextValue = "Значение по умолчанию"; } public ICommand ClickCommand { get { return _clickCommand ?? (new RelayCommand(() => Save(), _canExecute)); } } public MainViewModel() { _items = new List { "Test1", "Test2", "Test3" }; _selectedValue = _items.First(); _textValue = "Значение по умолчанию"; _canExecute = true; } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } public class RelayCommand : ICommand { private Action _action; private bool _canExecute; public RelayCommand(Action action, bool canExecute) { _action = action; _canExecute = canExecute; } public bool CanExecute(object parameter) { return _canExecute; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { _action(); } }

另外我们需要这个:

 private readonly MainViewModel _viewModel; public MainWindow() { InitializeComponent(); _viewModel = new MainViewModel(); this.DataContext = _viewModel; } 
Interesting Posts