forked from elmish/Elmish.WPF
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Elmish.WPF.Samples.Sticky.Program | ||
|
||
open Serilog | ||
open Serilog.Extensions.Logging | ||
open Elmish.WPF | ||
|
||
type Model = | ||
{ Count: int | ||
StepSize: int } | ||
|
||
type Msg = | ||
| Increment | ||
| Decrement | ||
| SetStepSize of int | ||
| Reset | ||
|
||
let init = | ||
{ Count = 0 | ||
StepSize = 1 } | ||
|
||
let canReset = (<>) init | ||
|
||
let update msg m = | ||
match msg with | ||
| Increment -> { m with Count = m.Count + m.StepSize } | ||
| Decrement -> { m with Count = m.Count - m.StepSize } | ||
| SetStepSize x -> { m with StepSize = x } | ||
| Reset -> init | ||
|
||
let bindings () : Binding<Model, Msg> list = [ | ||
"CounterValue" | ||
|> Binding.id | ||
|> Binding.sticky (fun v -> v % 2 = 0) | ||
|> Binding.mapModel (fun m -> m.Count) | ||
"Increment" |> Binding.cmd Increment | ||
"Decrement" |> Binding.cmd Decrement | ||
"StepSize" |> Binding.twoWay( | ||
(fun m -> float m.StepSize), | ||
int >> SetStepSize) | ||
"Reset" |> Binding.cmdIf(Reset, canReset) | ||
] | ||
|
||
let designVm = ViewModel.designInstance init (bindings ()) | ||
|
||
let main window = | ||
|
||
let logger = | ||
LoggerConfiguration() | ||
.MinimumLevel.Override("Elmish.WPF.Update", Events.LogEventLevel.Verbose) | ||
.MinimumLevel.Override("Elmish.WPF.Bindings", Events.LogEventLevel.Verbose) | ||
.MinimumLevel.Override("Elmish.WPF.Performance", Events.LogEventLevel.Verbose) | ||
.WriteTo.Console() | ||
.CreateLogger() | ||
|
||
WpfProgram.mkSimple (fun () -> init) update bindings | ||
|> WpfProgram.withLogger (new SerilogLoggerFactory(logger)) | ||
|> WpfProgram.startElmishLoop window |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0-windows</TargetFramework> | ||
<UseWpf>true</UseWpf> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog" Version="2.9.0" /> | ||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Elmish.WPF\Elmish.WPF.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Application x:Class="Elmish.WPF.Samples.Sticky.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
</Application.Resources> | ||
</Application> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Windows; | ||
|
||
namespace Elmish.WPF.Samples.Sticky | ||
{ | ||
public partial class App : Application | ||
{ | ||
public App() | ||
{ | ||
this.Activated += StartElmish; | ||
} | ||
|
||
private void StartElmish(object sender, EventArgs e) | ||
{ | ||
this.Activated -= StartElmish; | ||
Program.main(MainWindow); | ||
} | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Window x:Class="Elmish.WPF.Samples.Sticky.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:vm="clr-namespace:Elmish.WPF.Samples.Sticky;assembly=Sticky.Core" | ||
Title="Sticky" | ||
Height="120" | ||
Width="500" | ||
WindowStartupLocation="CenterScreen" | ||
mc:Ignorable="d" | ||
d:DataContext="{x:Static vm:Program.designVm}"> | ||
<StackPanel Orientation="Vertical"> | ||
<TextBlock Text="The counter value binding is sticky to even numbers"/> | ||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,25,0,0"> | ||
<TextBlock Text="{Binding CounterValue, StringFormat='Counter value: {0}'}" Width="110" Margin="0,5,10,5" /> | ||
<Button Command="{Binding Decrement}" Content="-" Margin="0,5,10,5" Width="30" /> | ||
<Button Command="{Binding Increment}" Content="+" Margin="0,5,10,5" Width="30" /> | ||
<TextBlock Text="{Binding StepSize, StringFormat='Step size: {0}'}" Width="70" Margin="0,5,10,5" /> | ||
<Slider Value="{Binding StepSize}" TickFrequency="1" Maximum="10" Minimum="1" IsSnapToTickEnabled="True" Width="100" Margin="0,5,10,5" /> | ||
<Button Command="{Binding Reset}" Content="Reset" Margin="0,5,10,5" Width="50" /> | ||
</StackPanel> | ||
</StackPanel> | ||
</Window> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Windows; | ||
|
||
namespace Elmish.WPF.Samples.Sticky { | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0-windows</TargetFramework> | ||
<UseWpf>true</UseWpf> | ||
<OutputType>Exe</OutputType> | ||
<DisableWinExeOutputInference>true</DisableWinExeOutputInference> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Sticky.Core\Sticky.Core.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |