2
FsXamlを使用してF#でWPFを使用しています。私は、実行時に次のエラーでクラッシュします、その時点で、にWindowsFormsHostコントロールを追加するまでメインウィンドウには、作品:WindowsFormsHostコントロールをMainWindowに追加すると、exeがクラッシュする
Unhandled Exception: System.Xaml.XamlObjectWriterException: Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}WindowsFormsHost'.
at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at [email protected](String file, Object root, Stream resStream, Unit unitVar)
at FsXaml.InjectXaml.from(String file, Object root)
at Program.Win.InitializeComponent()
at Program.Win..ctor()
は私がwinformshostを認識するXAMLやアプリを追加する必要があるものはありますか? C#で生成されたxamlは、C#アプリケーションで動作します。 F#アプリは、内部にwinformshostがない場合に機能します。 C#とF#xamlsの違いはxローカルの名前空間の参照です。
MainWindow.xaml:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="124" VerticalAlignment="Top" Width="217"/>
<WindowsFormsHost HorizontalAlignment="Left" Height="123" Margin="49,171,0,0" VerticalAlignment="Top" Width="394"/>
</Grid>
</Window>
App.xaml
<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>
Program.fs:
open System
open System.Windows
open FsXaml
open Microsoft.FSharp.Control
open System.Windows.Forms
open System.Windows.Forms.Integration
open FSharp.Charting
open FSharp.Charting.ChartTypes
type App = XAML<"App.xaml">
type Win = XAML<"MainWindow.xaml">
[<STAThread>]
[<EntryPoint>]
let main _ =
let app = App()
let win = Win()
win.button.Content <- "Click!"
win.button.MouseRightButtonDown.Add (fun _ -> MessageBox.Show("OK") |> ignore)
app.Run win |> ignore
0
ので、WinFormsのために: 'のxmlns:WFは= "clrnamespace:のSystem.Windows.Forms;アセンブリ=のSystem.Windows.Forms"'とwinformshostのためあなたが指摘した通りです。素晴らしい仕事をした。 – s952163
'Integration'、' xmlns:wfi = "clr-namespaceを追加する必要があります:System.Windows.Forms.Integration; assembly = WindowsFormsIntegration" – George