I'm trying to learn ReactiveUI so I'm making example app, but I'm having problem with InvokeCommand
. Basically every time SearchPhrase
property is changed my ShowSearchPhraseCommand
should be invoked.
Here is my View:
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal"
VerticalAlignment="Center" >
<TextBox Width="100" Height="20"
Text="{Binding Path=SearchPhrase, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
ViewModel:
public ReactiveCommand ShowSearchPhraseCommand { get; private set; }
string _searchPhrase;
public string SearchPhrase
{
get { return _searchPhrase; }
set { this.RaiseAndSetIfChanged(ref _searchPhrase, value); }
}
public SecondViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
// Commands
ShowSearchPhraseCommand = ReactiveCommand.Create(() => ShowSearchPhraseCommandHandler(SearchPhrase));
// WhenAny
this.WhenAnyValue(x => x.SearchPhrase).Where(x => !string.IsNullOrWhiteSpace(x)).InvokeCommand(ShowSearchPhraseCommand);
}
private void ShowSearchPhraseCommandHandler(string searchPhrase)
{
Debug.WriteLine($"Phrase: {searchPhrase}");
}
And here is my problem: