F#ã§WPFããã¨ãã®Tipsã¨ã(ãã®2)
F#ã§WPFããã¨ãã®Tipsã¨ã(ãã®1)ã®ç¶ç·¨ã§ãã
æ·»ä»ããããã£ã®ä½ãæ¹
F#ã§æ·»ä»ããããã£ãä½ãã«ã¯ãæ·»ä»ããããã£ã®æ¬ä½ã¯ããããã£ã§ã¯ãªããã£ã¼ã«ãã«ä¿æããå¿ è¦ãããããã§ãã
// ãã¡ãªä¾ type Sample private () = static member SomeValueProperty = DependencyProperty.RegisterAttached("SomeValue", typeof<string>, typeof<Sample>, FrameworkPropertyMetaData("", Sample.OnSomeValueChanged)) static member GetSomeValue(obj: DependencyObject) = obj.GetValue(Sample.SomeValueProperty) :?> string static member SetSomeValue(obj: DependencyObject, value: string) = obj.SetValue(Sample.SomeValueProperty, value) static member OnSomeValueChanged = PropertyChangedCallback(fun sender e -> // ããããã£ãå¤æ´ãããã¨ãã®å¦ç )
ãã®ã³ã¼ãã¯ã³ã³ãã¤ã«ã¯éãã¾ããããã®æ·»ä»ããããã£ã«XAMLå ã§Bindingãããã¨ããã¨ã
'Button' ã³ã¬ã¯ã·ã§ã³å
㧠'Binding' ã使ç¨ãããã¨ã¯ã§ãã¾ããã'Binding' ã¯ãDependencyObject ã® DependencyProperty ã§ã®ã¿è¨å®ã§ãã¾ãã
ã¨ããã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ãã
ããããã£ã§ã¯ãªããã£ã¼ã«ãã使ãã¨ãã¾ãããã¾ãã
type Sample private () = // ä¸æ¦staticãªãã£ã¼ã«ãã«ä¿æãã¦ããã¦ã static let someValueProperty = DependencyProperty.RegisterAttached("SomeValue", typeof<string>, typeof<Sample>, FrameworkPropertyMetaData("", Sample.OnSomeValueChanged)) // ããããã£ã®å¤ã¨ãã¦ä¿æãããã£ã¼ã«ããè¨å® static member SomeValueProperty = someValueProperty static member GetSomeValue(obj: DependencyObject) = obj.GetValue(Sample.SomeValueProperty) :?> string static member SetSomeValue(obj: DependencyObject, value: string) = obj.SetValue(Sample.SomeValueProperty, value) static member OnSomeValueChanged = PropertyChangedCallback(fun sender e -> // ããããã£ãå¤æ´ãããã¨ãã®å¦ç )
æ·»ä»ããããã£ãF#ã§æ¸ãããããWPFã®ããªãã®é¨åãF#ã®ã¿ã§å®çµã§ããã¨æããã¾ãã Full F#ã§WPFãããªãç¾å®å³ã帯ã³ã¦ãã¾ããã 足ããªãã®ã¯å種ã¦ã¼ãã£ãªãã£ãªã®ã§ããã®è¾ºã®åå®è£ ãè¦ã§ãªã人ã§ããã°ãååé¸æè¢ã«å ¥ã£ã¦ããç°å¢ã¯ãã§ã«æ´ã£ãã¨è¨ããã§ãããã
å¥Windowã®éãæ¹
ä»ã®ã¨ãããä¸çªæ軽ã«å¥Windowãéãã«ã¯ãXAML Type Providerã使ãã®ãããã§ãããã
ã¾ãã¯XAMLãä½ãå¿ è¦ãããã¾ãããF#ã®ããã¸ã§ã¯ãã§ã¯XAMLã®ã¢ã¤ãã ãã³ãã¬ã¼ãããªãããããGeneralãã®ãXMLãã¡ã¤ã«ããé¸ãã§ãã¡ã¤ã«ã®æ¡å¼µåãxamlã«å¤æ´ãã¾ãã 注æç¹ã¨ãã¦ããã®æ¹æ³ã§è¿½å ãããã¡ã¤ã«ã¯ããã«ãã¢ã¯ã·ã§ã³ãããNoneãã«ãªã£ã¦ããã®ã§ããResourceãã«å¤æ´ãã¦ããå¿ è¦ãããã¾ãã
ãF# Empty Windows App (WPF)ããã³ãã¬ã¼ãã§ããã¸ã§ã¯ããä½ã£ãå ´åã
type OtherView = XAML<"OtherWindow.xaml">
ã¨ãã¦Viewã表ãåãä½ã£ã¦ããã¦ãä½ããã®ã³ãã³ãå
ã§ãã®åã®ãªãã¸ã§ã¯ããçæã㦠Show
(ããã㯠ShowDialog
)ãå¼ã³åºãã¾ãã
member this.OnClick = this.Factory.CommandSync (fun () -> let view = OtherView() view.Root.Show() )
ã¡ãªã¿ã«ããF# Empty Windows App (WPF)ããã³ãã¬ã¼ãã§å°å
¥ãããFsXaml.Wpfã¯å¤ã(0.9.9)ãããããã±ã¼ã¸ãæ´æ°(ç¾æç¹ã§ã¯2.1.0)ããã¨ãã«ããéããªããªãã¾ãã
ãã«ããéãããã«ã¯ãRoot
ããããã£ã¸ã®ã¢ã¯ã»ã¹ãæ¶ãã¦ãã ããã
member this.OnClick = this.Factory.CommandSync (fun () -> let view = OtherView() view.Show() )
App.fsãã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªãã®ã§ããã¡ãã® Root
ãåé¤ãã¾ãããã
[<STAThread>] [<EntryPoint>] let main argv = App().Run()