Skip to content

Instantly share code, notes, and snippets.

View ViewModel.cs
class ViewModel
{
public ReactiveProperty<string> Input { get; }
public ReactiveProperty<string> Output { get; }
public ViewModel()
{
Input = new ReactiveProperty("");
Output = Input
.Delay(TimeSpan.FromSecond(1)) // Using a Rx method.
View MainPage.xaml
<TextBlock Text="{Binding Message.Value}" />
View HowToUse.cs
var viewModel = new SomeViewModel();
viewModel.Message.Value = "Hello world"; // set a value
Console.WriteLine(viewModel.Message.Value); // get a value
View ReactiveProperty.cs
public interface IReactiveProperty<T> : IObservable<T>, INotifyPropertyChanged
{
T Value { get; set; }
}
public class ReactiveProperty<T> : IReactiveProperty<T>
{
public event PropertyChangedEventHandler PropertyChanged;
private T _value;
View ReactivePropertyViewModel.cs
public class SomeViewModel // You don't need implementation of INotifyPropertyChanged
{
public ReactiveProperty<string> Message { get; } = new ReactiveProperty<string>();
}
View ViewModel.cs
public class SomeViewModel : BindableBase
{
private string _message;
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}
}
View BindableBase.cs
public class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual bool SetProperty<T>(ref T field, T value, [CallerMemberName]string propertyName)
{
if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
storage = value;
RaisePropertyChanged(propertyName);
return true;
View ViewModel.cs
public class SomeViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _message;
public string Message
{
get { return _message; }
set
{
View sample.cs
using Moq;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp10
{
class Program
{
View Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unity;
using Unity.Lifetime;
namespace LINQLab
{
class Program