public MainViewModel() { SayHelloCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => SayHello()) .OnCanExecute(() => !string.IsNullOrWhiteSpace(Name)) .Observe(this, nameof(Name)) .Build(); }
public void DelegateCommandBuilder_using_invalid_full_nested_path_should_not_fail() { var sut = new DelegateCommandBuilder(); CommandData cd; var succeeded = sut.TryGenerateCommandData(new PropertyPath("Invalid.ThisIsInvalid"), new TestDataContext(), out cd); Assert.IsFalse(succeeded); Assert.IsNull(cd); }
public void DelegateCommandBuilder_using_nested_PropertyPath_that_ends_with_Command_should_succeed() { var sut = new DelegateCommandBuilder(); CommandData cd; var succeeded = sut.TryGenerateCommandData(new PropertyPath("MyProperty.OtherThatEndsWithCommand"), new TestDataContext(), out cd); Assert.IsTrue(succeeded); Assert.IsTrue(cd.FastDelegate != null); }
public void DelegateCommandBuilder_using_simple_method_on_nested_property_should_generate_CommandData() { var sut = new DelegateCommandBuilder(); CommandData cd; var succeeded = sut.TryGenerateCommandData(new PropertyPath("MyProperty.DoSomethingElse"), new TestDataContext(), out cd); Assert.IsTrue(succeeded); Assert.IsTrue(cd.FastDelegate != null); }
public PublisherViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; PublishCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => Publish()) .OnCanExecute(() => !string.IsNullOrEmpty(Message)) .Observe(this, nameof(Message)) .Build(); }
public void DelegateCommandBuilder_using_PropertyPath_that_ends_with_Command_but_method_doesnt_should_succeed() { //this is for backward compatibility var sut = new DelegateCommandBuilder(); CommandData cd; var succeeded = sut.TryGenerateCommandData(new PropertyPath("WithoutCommandSuffixCommand"), new TestDataContext(), out cd); Assert.IsTrue(succeeded); Assert.IsTrue(cd.FastDelegate != null); }
public MainViewModel(Company company) { _company = company; _validation = new ValidationAdapter(OnErrorsChanged); _validation.Validator = SetupValidator(); SaveCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => Save()) .OnCanExecute(() => CanSave) .Observe(this, nameof(CanSave)) .Build(); }
public void DelegateCommandBuilder_using_simple_method_with_no_Command_suffix_should_generate_CommandData_with_exact_match() { var sut = new DelegateCommandBuilder(); var dc = new TestDataContext(); var methodToInvoke = "DoSomething"; CommandData cd; var succeeded = sut.TryGenerateCommandData(new PropertyPath(methodToInvoke), dc, out cd); cd.FastDelegate(dc, null); Assert.AreEqual(methodToInvoke, cd.MethodName); }
public ShellViewModel(Func <TabViewModel> createTabViewModel) { if (createTabViewModel == null) { throw new ArgumentNullException(nameof(createTabViewModel)); } _createTabViewModel = createTabViewModel; OpenTabCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => OpenTab()) .Build(); CloseTabCommand = DelegateCommandBuilder.WithParameter <TabViewModel>() .OnExecute(item => DeactivateItem(item, true)) .Build(); }
public ShellViewModel() { ExecuteCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => OnExecute()) .Build(); UIContextRunCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => OnUIContextRun()) .Build(); TaskRunCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => OnTaskRun()) .Build(); AsyncCommand = DelegateCommandBuilder.NoParameter() .OnExecute(() => OnAsync()) .Build(); }
public MainPageViewModel() { Characters = new BindableCollection <CharacterViewModel> { new CharacterViewModel("Arya Stark", "ms-appx:///resources/images/arya.jpg"), new CharacterViewModel("Catelyn Stark", "ms-appx:///resources/images/catelyn.jpg"), new CharacterViewModel("Cercei Lannister", "ms-appx:///resources/images/cercei.jpg"), new CharacterViewModel("Jamie Lannister", "ms-appx:///resources/images/jamie.jpg"), new CharacterViewModel("Jon Snow", "ms-appx:///resources/images/jon.jpg"), new CharacterViewModel("Rob Stark", "ms-appx:///resources/images/rob.jpg"), new CharacterViewModel("Sandor Clegane", "ms-appx:///resources/images/sandor.jpg"), new CharacterViewModel("Sansa Stark", "ms-appx:///resources/images/sansa.jpg"), new CharacterViewModel("Tyrion Lannister", "ms-appx:///resources/images/tyrion.jpg") }; CharacterSelectedCommand = DelegateCommandBuilder.WithParameter <CharacterViewModel>() .OnExecute(p => CharacterSelected(p)) .Build(); }