This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewModel : INotifyPropertyChanged | |
{ | |
public ViewModel() | |
{ | |
Clear = new Command(() => Name = string.Empty); | |
} | |
public ICommand Clear { get; } | |
public string Greeting => $"Hello, {Name}!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackPanel> | |
<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |
<TextBlock Text="{Binding Greeting, Mode=OneWay}"/> | |
<Button Content="Clear" Command="{Binding Clear}"/> | |
</StackPanel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReactiveViewModel : ReactiveObject | |
{ | |
public ReactiveViewModel() | |
{ | |
Clear = ReactiveCommand.Create(() => { Name = string.Empty; }); | |
this.WhenAnyValue(x => x.Name) | |
.Select(name => $"Hello, {name}!") | |
.ToProperty(this, x => x.Greeting, out greeting); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReactivePropertyViewModel | |
{ | |
public ReadOnlyReactiveProperty<string> Greeting { get; } | |
public ReactiveProperty<string> Name { get; } | |
public ReactiveCommand Clear { get; } | |
public ReactivePropertyViewModel() | |
{ | |
Clear = new ReactiveCommand(); | |
Clear.Subscribe(() => Name.Value = string.Empty); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackPanel> | |
<!-- Note the ".Value" suffix added to "Name" and "Greeting" properties. --> | |
<TextBox Text="{Binding Name.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> | |
<TextBlock Text="{Binding Greeting.Value, Mode=OneWay}"/> | |
<Button Content="Clear" Command="{Binding Clear}"/> | |
</StackPanel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AddINotifyPropertyChangedInterface] | |
public class FodyReactiveViewModel | |
{ | |
public ReactiveCommand<Unit, Unit> Clear { get; } | |
public string Greeting { get; private set; } | |
public string Name { get; set; } = string.Empty; | |
public FodyReactiveViewModel() | |
{ | |
Clear = ReactiveCommand.Create(() => { Name = string.Empty; }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class FeedbackViewModel : ReactiveObject, IActivatableViewModel | |
{ | |
public ViewModelActivator Activator { get; } = new ViewModelActivator(); | |
public ReactiveCommand<Unit, Unit> Submit { get; } | |
[Reactive] public bool HasErrors { get; private set; } | |
[Reactive] public string Elapsed { get; private set; } = string.Empty; | |
[Reactive] public string Title { get; set; } = string.Empty; | |
[Reactive] public int TitleLength { get; private set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackPanel Width="300" VerticalAlignment="Center"> | |
<TextBlock Text="Feedback" Style="{StaticResource TitleTextBlockStyle}" /> | |
<TextBox Text="{x:Bind ViewModel.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" | |
MaxLength="{x:Bind ViewModel.TitleLengthMax}" | |
PlaceholderText="Title" /> | |
<TextBlock Style="{StaticResource CaptionTextBlockStyle}" Margin="0 5"> | |
<Run Text="{x:Bind ViewModel.TitleLength, Mode=OneWay}"/> | |
<Run Text="letters used from"/> | |
<Run Text="{x:Bind ViewModel.TitleLengthMax}"/> | |
</TextBlock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StackLayout Margin="20"> | |
<Entry Text="{Binding Title, Mode=TwoWay}" Placeholder="Title"/> | |
<StackLayout Orientation="Horizontal"> | |
<Label Text="{Binding TitleLength, Mode=OneWay}"/> | |
<Label Text="letters used from"/> | |
<Label Text="{Binding TitleLengthMax, Mode=OneWay}"/> | |
</StackLayout> | |
<Entry Text="{Binding Message, Mode=TwoWay}" Placeholder="Message"/> | |
<StackLayout Orientation="Horizontal"> | |
<Label Text="{Binding MessageLength, Mode=OneWay}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void ShouldValidateFormAndSendFeedback() | |
{ | |
// Create stubs for all dependencies and inject them. | |
var sender = Substitute.For<ISender>(); | |
var clock = Substitute.For<IClock>(); | |
var feedback = new FeedbackViewModel(sender, clock); | |
feedback.HasErrors.Should().BeTrue(); | |
// Emulate user input. |
OlderNewer