KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm inexperienced, especially at MVVM, but trying to use ReactiveUI, and I'm not understanding the examples that I'm finding that demonstrate ReactiveCommand. I have used ICommand / DelegateCommand one time before, but this is different, and I'm not getting it. What I'm trying to do is really simple. Click a button in the view, and have that execute a method in the view model. The examples that I'm finding all involve IObservable<>, and I don't get that, as they don't explanations that are geared to the total noob that I am. Basically, I'm trying to use this as a learning experience, and what I'd ideally like to do is bind the button's Command property in xaml to a command (however that works, I don't know), which causes a method to execute. No collections, I'd just be passing a single int variable. Thanks for the help. I really appreciate it. Edit - Below appears code using Paul Betts' suggestions: C# public ReactiveCommand AddToDailyUsed { get; protected set; } public MainPageVM() { Initialize(); AddToDailyUsed = new ReactiveCommand(); AddToDailyUsed.Subscribe(AddToTodayUsedAction => this.AddToDailyUsedExecuted()); } private object AddToDailyUsedExecuted() { MessageBox.Show("AddToDailyUsedAction"); return null; } private void AddToDailyUsedAction(object obj) { MessageBox.Show("AddToDailyUsedAction"); } XAML <Button Content="{Binding Strings.add, Source={StaticResource LocalStrings}}" Command="{Binding AddToTodayUsed}" Margin="-5,-10, -10,-10" Grid.Row="3" Grid.Column="2" /> Obviously I'm missing something. I inserted break points at the AddToDailyUsedExecuted and AddToDailyUsedAction methods, and they are never reached. Edit Constructor for code behind the view: MainPageVM mainPageVM = new MainPageVM(); public MainPage(
Tags (comma-separated)
Save Edits
Cancel