-1
我在學習ReactiveUI,所以我正在製作示例應用程序,但我遇到了問題InvokeCommand
。基本上每次SearchPhrase
屬性都改變了我的ShowSearchPhraseCommand
應該被調用。WPF - ReactiveUI InvokeCommand不工作
這是我的觀點:
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal"
VerticalAlignment="Center" >
<TextBox Width="100" Height="20"
Text="{Binding Path=SearchPhrase, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
視圖模型:
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}");
}
,這裏是我的問題: