Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added design-time view models for all samples #249

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ Then use the following attributes wherever you need a design-time VM:

When targeting .NET Framework, “Project code” must be enabled in the XAML designer for this to work.

When targeting .NET Core 3, the designer is buggy when it comes to design-time view models as used above. If you don’t get the data you expect, try to remove and re-add (e.g. undo) the `d:DataContext` line. That should make it work. You will have to do this as often as needed.
When targeting .NET Core 3, a bug in the XAML designer causes design-time data to not be displayed through `DataContext` bindings. See [this issue](https://developercommunity.visualstudio.com/content/problem/1133390/design-time-data-in-datacontext-binding-not-displa.html) for more details.

#### Can I open new windows/dialogs?

Expand Down
8 changes: 4 additions & 4 deletions src/Elmish.WPF.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.352
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "SingleCounter", "Samples\SingleCounter\SingleCounter.fsproj", "{2DBB8062-2843-43A0-B73C-4777A30BD4FF}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Elmish.WPF", "Elmish.WPF\Elmish.WPF.fsproj", "{8C6E8D34-7205-4C57-9722-87E30E4FC5CE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{BBAFEB1E-93C0-4C7E-8E0A-026BB05C88EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SingleCounter.Views", "Samples\SingleCounter.Views\SingleCounter.Views.csproj", "{55F79BA4-8265-4612-8354-D04F91BF9B03}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "SingleCounter", "Samples\SingleCounter\SingleCounter.fsproj", "{2DBB8062-2843-43A0-B73C-4777A30BD4FF}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Elmish.WPF", "Elmish.WPF\Elmish.WPF.fsproj", "{8C6E8D34-7205-4C57-9722-87E30E4FC5CE}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "UiBoundCmdParam", "Samples\UiBoundCmdParam\UiBoundCmdParam.fsproj", "{9581A1DE-70A6-4AC2-AF65-FD6E95F3A983}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UiBoundCmdParam.Views", "Samples\UiBoundCmdParam.Views\UiBoundCmdParam.Views.csproj", "{574786BE-3A84-4A0F-99DE-0FB10ED4161F}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseWpf>true</UseWpf>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventBindingsAndBehaviors\EventBindingsAndBehaviors.fsproj" />
</ItemGroup>

</Project>
TysonMN marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 6 additions & 1 deletion src/Samples/EventBindingsAndBehaviors.Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<Window x:Class="Elmish.WPF.Samples.EventBindingsAndBehaviors.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:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Elmish.WPF.Samples.EventBindingsAndBehaviors"
xmlns:vm="clr-namespace:Elmish.WPF.Samples.EventBindingsAndBehaviors;assembly=EventBindingsAndBehaviors"
Title="EventBindings"
Height="450"
Width="400"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.designVm}">
<StackPanel Margin="15" HorizontalAlignment="Center">
<TextBlock Text="Switch focus between these two inputs." Margin="0,0,0,10" TextAlignment="Center" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
Expand Down
11 changes: 11 additions & 0 deletions src/Samples/EventBindingsAndBehaviors.Views/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using Elmish.WPF.Samples.EventBindingsAndBehaviors;
using static Elmish.WPF.Samples.EventBindingsAndBehaviors.Program;

namespace EventBindingsAndBehaviors.Views {
public static class Program {
[STAThread]
public static void Main() =>
main(new MainWindow());
}
}
cmeeren marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWpf>true</UseWpf>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -13,7 +12,6 @@

<ItemGroup>
<ProjectReference Include="..\..\Elmish.WPF\Elmish.WPF.fsproj" />
<ProjectReference Include="..\EventBindingsAndBehaviors.Views\EventBindingsAndBehaviors.Views.csproj" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Samples/EventBindingsAndBehaviors/Program.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Elmish.WPF.Samples.EventBindingsAndBehaviors.Program

open System
open Elmish
open Elmish.WPF
open System.Windows
Expand Down Expand Up @@ -67,11 +66,12 @@ let bindings () : Binding<Model, Msg> list = [
"MousePosition" |> Binding.oneWay (fun m -> sprintf "%dx%d" m.MousePosition.X m.MousePosition.Y)
]

let designVm = ViewModel.designInstance (init ()) (bindings ())

[<EntryPoint; STAThread>]
let main _ =

let main window =
Program.mkSimpleWpf init update bindings
|> Program.withConsoleTrace
|> Program.runWindowWithConfig
{ ElmConfig.Default with LogConsole = true; Measure = true }
(MainWindow())
window
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseWpf>true</UseWpf>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\FileDialogs.CmdMsg\FileDialogs.CmdMsg.fsproj" />
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion src/Samples/FileDialogs.CmdMsg.Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Window x:Class="Elmish.WPF.Samples.FileDialogs.CmdMsg.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.FileDialogs.CmdMsg;assembly=FileDialogs.CmdMsg"
Title="File dialogs"
Height="400"
Width="500"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.designVm}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,25,0,0">
<StackPanel>
<TextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Width="200" Height="100" TextWrapping="Wrap" AcceptsReturn="True" Margin="0,5,10,5" />
Expand Down
11 changes: 11 additions & 0 deletions src/Samples/FileDialogs.CmdMsg.Views/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using Elmish.WPF.Samples.FileDialogs.CmdMsg;
using static Elmish.WPF.Samples.FileDialogs.CmdMsg.Program;

namespace FileDialogs.CmdMsg.Views {
public static class Program {
[STAThread]
public static void Main() =>
main(new MainWindow());
}
}
2 changes: 0 additions & 2 deletions src/Samples/FileDialogs.CmdMsg/FileDialogs.CmdMsg.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWpf>true</UseWpf>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -13,7 +12,6 @@

<ItemGroup>
<ProjectReference Include="..\..\Elmish.WPF\Elmish.WPF.fsproj" />
<ProjectReference Include="..\FileDialogs.CmdMsg.Views\FileDialogs.CmdMsg.Views.csproj" />
</ItemGroup>

</Project>
8 changes: 5 additions & 3 deletions src/Samples/FileDialogs.CmdMsg/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ open Core
open Platform


let designVm = ViewModel.designInstance (init () |> fst) (bindings ())


let timerTick dispatch =
let timer = new Timers.Timer(1000.)
timer.Elapsed.Add (fun _ -> dispatch (SetTime DateTimeOffset.Now))
timer.Start()


[<EntryPoint; STAThread>]
let main _ =
let main window =
Program.mkProgramWpfWithCmdMsg init update bindings toCmd
|> Program.withSubscription (fun _ -> Cmd.ofSub timerTick)
|> Program.withConsoleTrace
|> Program.runWindowWithConfig
{ ElmConfig.Default with LogConsole = true; Measure = true }
(MainWindow())
window
5 changes: 5 additions & 0 deletions src/Samples/FileDialogs.Views/FileDialogs.Views.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseWpf>true</UseWpf>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\FileDialogs\FileDialogs.fsproj" />
</ItemGroup>

</Project>
7 changes: 6 additions & 1 deletion src/Samples/FileDialogs.Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Window x:Class="Elmish.WPF.Samples.FileDialogs.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.FileDialogs;assembly=FileDialogs"
Title="File dialogs"
Height="400"
Width="500"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.designVm}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,25,0,0">
<StackPanel>
<TextBox Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Width="200" Height="100" TextWrapping="Wrap" AcceptsReturn="True" Margin="0,5,10,5" />
Expand Down
11 changes: 11 additions & 0 deletions src/Samples/FileDialogs.Views/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using Elmish.WPF.Samples.FileDialogs;
using static Elmish.WPF.Samples.FileDialogs.Program;

namespace FileDialogs.Views {
public static class Program {
[STAThread]
public static void Main() =>
main(new MainWindow());
}
}
2 changes: 0 additions & 2 deletions src/Samples/FileDialogs/FileDialogs.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWpf>true</UseWpf>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -13,7 +12,6 @@

<ItemGroup>
<ProjectReference Include="..\..\Elmish.WPF\Elmish.WPF.fsproj" />
<ProjectReference Include="..\FileDialogs.Views\FileDialogs.Views.csproj" />
</ItemGroup>

</Project>
15 changes: 9 additions & 6 deletions src/Samples/FileDialogs/Program.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Elmish.WPF.Samples.FileDialogs.Program
module Elmish.WPF.Samples.FileDialogs.Program

open System
open System.IO
Expand All @@ -12,12 +12,13 @@ type Model =
{ CurrentTime: DateTimeOffset
Text: string
StatusMsg: string }



let init () =
{ CurrentTime = DateTimeOffset.Now
Text = ""
StatusMsg = "" },
Cmd.none
[]

type Msg =
| SetTime of DateTimeOffset
Expand Down Expand Up @@ -88,17 +89,19 @@ let bindings () : Binding<Model, Msg> list = [
]


let designVm = ViewModel.designInstance (init () |> fst) (bindings ())


let timerTick dispatch =
let timer = new Timers.Timer(1000.)
timer.Elapsed.Add (fun _ -> dispatch (SetTime DateTimeOffset.Now))
timer.Start()


[<EntryPoint; STAThread>]
let main _ =
let main window =
Program.mkProgramWpf init update bindings
|> Program.withSubscription (fun _ -> Cmd.ofSub timerTick)
|> Program.withConsoleTrace
|> Program.runWindowWithConfig
{ ElmConfig.Default with LogConsole = true; Measure = true }
(MainWindow())
window
7 changes: 6 additions & 1 deletion src/Samples/NewWindow.Views/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Window x:Class="Elmish.WPF.Samples.NewWindow.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.NewWindow;assembly=NewWindow"
Title="Multiple windows"
Height="250"
Width="300"
WindowStartupLocation="CenterScreen">
WindowStartupLocation="CenterScreen"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.mainDesignVm}">
<Window.Resources>
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="VisibilityConverter" />
Expand Down
5 changes: 5 additions & 0 deletions src/Samples/NewWindow.Views/NewWindow.Views.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
<UseWpf>true</UseWpf>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\NewWindow\NewWindow.fsproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/Samples/NewWindow.Views/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using Elmish.WPF.Samples.NewWindow;
using static Elmish.WPF.Samples.NewWindow.Program;

namespace NewWindow.Views {
public static class Program {
[STAThread]
public static void Main() =>
main(new MainWindow(), () => new Window1(), () => new Window2());
}
}
7 changes: 6 additions & 1 deletion src/Samples/NewWindow.Views/Window1.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Window x:Class="Elmish.WPF.Samples.NewWindow.Window1"
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.NewWindow;assembly=NewWindow"
Width="400"
Height="400"
Title="Window 1">
Title="Window 1"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.window1DesignVm}">
<StackPanel VerticalAlignment="Center" Width="300">
<TextBlock
TextWrapping="Wrap">
Expand Down
7 changes: 6 additions & 1 deletion src/Samples/NewWindow.Views/Window2.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<Window x:Class="Elmish.WPF.Samples.NewWindow.Window2"
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.NewWindow;assembly=NewWindow"
Width="500"
Height="500"
Title="Window 2">
Title="Window 2"
mc:Ignorable="d"
d:DataContext="{x:Static vm:Program.window2DesignVm}">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
</Window.Resources>
Expand Down
2 changes: 0 additions & 2 deletions src/Samples/NewWindow/NewWindow.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWpf>true</UseWpf>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -13,7 +12,6 @@

<ItemGroup>
<ProjectReference Include="..\..\Elmish.WPF\Elmish.WPF.fsproj" />
<ProjectReference Include="..\NewWindow.Views\NewWindow.Views.csproj" />
</ItemGroup>

</Project>
Loading