Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class DelegateCommand<T> : Command
- {
- private readonly Action<T> execute;
- private readonly Func<T, bool> canExecute;
- public DelegateCommand(Action<T> execute, Func<T, bool> canExecute)
- {
- this.execute = execute;
- this.canExecute = canExecute;
- }
- public override bool CanExecute(object parameter)
- {
- return (canExecute != null) ? canExecute((T)parameter) : true;
- }
- public override void Execute(object parameter)
- {
- execute((T)parameter);
- }
- }
- public sealed class MainWindowViewModel : INotifyPropertyChanged {
- private string city;
- public MainWindowViewModel(... service) {
- this.service = service;
- ListCommand = new DelegateCommand<object>(obj => ListRealties, null);
- Realties = new ObservableCollection<Realty>();
- }
- public event PropertyChangedEventHandler PropertyChanged;
- public string City {
- get { return city; }
- set {
- if (value != city) {
- city = value;
- var handler = PropertyChanged;
- if (handler != null)
- handler(this, new PropertyChangedEventArgs("City"));
- }
- }
- }
- public ObservableCollection<Realty> Realties { get; private set; }
- private void ListRealties() {
- Realties.Clear();
- foreach (var realty in service.GetAllProperties(City))
- Realties.Add(new Realty(realty.Condition, realty.Street));
- }
- }
- <Window>
- <TextBox Text="{Binding City}"/>
- <ListBox ItemsSource="{Binding Realties}"/>
- <Button Command="{Binding ListCommand}" Content="Auflisten"/>
- </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement