Skip to content

Instantly share code, notes, and snippets.

View worldbeater's full-sized avatar
☦️

Artyom V. Gorchakov worldbeater

☦️
View GitHub Profile
<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}"/>
<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>
[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.
public sealed partial class FeedbackView : Page, IViewFor<FeedbackViewModel>
{
public static readonly DependencyProperty ViewModelProperty = DependencyProperty
.Register(nameof(ViewModel), typeof(FeedbackViewModel), typeof(FeedbackView), null);
public FeedbackView()
{
InitializeComponent();
ViewModel = new FeedbackViewModel(new UwpSender(), new Clock());
this.WhenActivated(disposables => { /* handle interactions, etc. */ });
module Program
open System
open Funogram.Bot
/// Handles all Telegram events.
let update context =
context.Update.UpdateId
|> printfn "Received update: %i"
@worldbeater
worldbeater / Commands.fs
Last active March 17, 2019 20:34
Funogram Greetings Bot
module Program
open Funogram.Bot
open Funogram.Api
open ExtCore.Control
open System
/// Handler for '/hello'.
let onHello context =
maybe {
public partial class FeedbackView : Form, IViewFor<FeedbackViewModel>
{
public FeedbackView()
{
InitializeComponent();
ViewModel = new FeedbackViewModel(new WinFormsSender(), new Clock());
this.WhenActivated(subscriptions =>
{
this.Bind(ViewModel, x => x.Title, x => x.TitleTextBox.Text)
.DisposeWith(subscriptions);
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; }
<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>
public class ViewModel : INotifyPropertyChanged
{
public ViewModel()
{
Clear = new Command(() => Name = string.Empty);
}
public ICommand Clear { get; }
public string Greeting => $"Hello, {Name}!";