Skip to content

Commit

Permalink
Merge pull request #576 from marner2/feature/improve_documentation_re…
Browse files Browse the repository at this point in the history
…adme

Improve documentation readme
  • Loading branch information
marner2 authored Sep 12, 2023
2 parents 1460514 + f3a1c30 commit 3d423c5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WPF done the Elmish Way

<img src="https://raw.githubusercontent.com/elmish/Elmish.WPF/master/logo/elmish-wpf-logo-ghreadme.png" width="300" align="right" />

[![NuGet version](https://img.shields.io/nuget/v/Elmish.WPF.svg)](https://www.nuget.org/packages/Elmish.WPF) [![NuGet downloads](https://img.shields.io/nuget/dt/Elmish.WPF.svg)](https://www.nuget.org/packages/Elmish.WPF) [![Build status](https://github.com/elmish/Elmish.WPF/workflows/master/badge.svg)](https://github.com/elmish/Elmish.WPF/actions/workflows/master.yml)
[![NuGet version](https://img.shields.io/nuget/v/Elmish.WPF.svg)](https://www.nuget.org/packages/Elmish.WPF) [![NuGet downloads](https://img.shields.io/nuget/dt/Elmish.WPF.svg)](https://www.nuget.org/packages/Elmish.WPF) [![Build status](https://github.com/elmish/Elmish.WPF/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/elmish/Elmish.WPF/actions/workflows/continuous_integration.yml)

**The good parts of MVVM (the data bindings) with the simplicity and robustness of an MVU architecture for the rest of your app. Never write an overly-complex ViewModel class again!**

Expand Down Expand Up @@ -152,7 +152,17 @@ See the [SingleCounter](https://github.com/elmish/Elmish.WPF/tree/master/src/Sam
open Elmish.WPF

let main window =
Program.mkSimpleWpf init update bindings
Program.mkSimple init update bindings
|> Program.runElmishLoop window
```

Alternatively, use a statically-typed view model at the top level.

```F#
open Elmish.WPF

let main window =
Program.mkSimpleT init update CounterViewModel
|> Program.runElmishLoop window
```

Expand Down Expand Up @@ -276,6 +286,29 @@ Then use the following attributes wherever you need a design-time VM:

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

If you are using static view models, make sure that the View Model type is in a namespace and add a default constructor that passes a model into `ViewModelArgs.simple`:

```F#
namespace ViewModels
type [<AllowNullLiteral>] AppViewModel (args) =
inherit ViewModelBase<AppModel, AppMsg>(args)
new() = AppViewModel(App.init () |> ViewModelArgs.simple)
```

Then use the following attributes just like you would in a normal C# MVVM project:

```XAML
<Window
...
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:ViewModels.SubModelStatic;assembly=MyAssembly"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=vm:AppViewModel, IsDesignTimeCreatable=True}">
```

##### .NET Core 3 workaround

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 details. One workaround is to add a `d:DataContext` binding alongside your normal `DataContext` binding. Another workaround is to change
Expand Down
4 changes: 3 additions & 1 deletion src/Elmish.WPF/Elmish.WPF.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>Embedded</DebugType>
<EmbedAllSources>True</EmbedAllSources>
<Authors>jsacks, cmeeren, TysonMN</Authors>
<Authors>jsacks, cmeeren, TysonMN, jmarner</Authors>
<Description>F# bindings for using Elmish in WPF</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/elmish/Elmish.WPF</PackageProjectUrl>
<PackageTags>WPF F# fsharp Elmish Elm</PackageTags>
<PackageIcon>elmish-wpf-logo-128x128.png</PackageIcon>
<Version>4.0.0-beta-53</Version>
<PackageReleaseNotes>https://github.com/elmish/Elmish.WPF/blob/master/RELEASE_NOTES.md</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!--Turn on warnings for unused values (arguments and let bindings) -->
<OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags>
</PropertyGroup>
Expand All @@ -29,6 +30,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Link="README.md" Pack="True" PackagePath="/" />
<None Include="elmish-wpf-logo-128x128.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
Expand Down

0 comments on commit 3d423c5

Please sign in to comment.