Skip to content

Instantly share code, notes, and snippets.

@bleis-tift
Last active July 1, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleis-tift/2a9f42ceed1e15af96af295417b1413a to your computer and use it in GitHub Desktop.
Save bleis-tift/2a9f42ceed1e15af96af295417b1413a to your computer and use it in GitHub Desktop.
module main
open System
open FsXaml
type App = XAML<"App.xaml">
[<STAThread>]
[<EntryPoint>]
let main argv =
App().Root.Run()
<Application
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>
// Library1プロジェクト
namespace Library1
open System.Windows
type Hoge () =
static let hogeProp =
DependencyProperty.RegisterAttached("Hoge", typeof<string>, typeof<Hoge>, PropertyMetadata("hoge"))
static member HogeProperty = hogeProp
static member GetHoge(obj: DependencyObject) =
obj.GetValue(Hoge.HogeProperty) :?> string
static member SetHoge(obj: DependencyObject, value: string) =
obj.SetValue(Hoge.HogeProperty, value)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ViewModels;assembly=FsEmptyWindowsApp1"
xmlns:hoge="clr-namespace:Library1;assembly=Library1"
xmlns:fsxaml="http://github.com/fsprojects/FsXaml"
Title="MVVM and XAML Type provider" Height="200" Width="400">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<Button hoge:Hoge.Hoge="{Binding Text}">btn</Button>
</Grid>
</Window>
namespace ViewModels
open System
open System.Windows
open FSharp.ViewModule
open FSharp.ViewModule.Validation
type MainViewModel() as self =
inherit ViewModelBase()
let text = self.Factory.Backing(<@ self.Text @>, "")
member __.Text with get () = text.Value and set (value) = text.Value <- value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment