尝试使用Loaded事件加载xaml组件时,我收到XAMLParseException。我不太确定如何为处理事件编写方法签名。 C#示例很清楚,但我不知道如何将其转换为F#版本。我将在下面加入我的第一次尝试。
ViewModel代码:
let theWindow = Application.LoadComponent(new Uri("/MyApp;component/MyWindow.xaml", UriKind.Relative)) :?> Window
XAML标题:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:MyApp.Converters;assembly=MyApp"
xmlns:local="clr-namespace:MyApp;assembly=MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Name="_theWindow"
WindowStartupLocation="CenterOwner"
Title="My App - Popup Window"
Loaded="Window_Loaded"
Icon="MyApp;component/icons/MyApp.ico"
Width="484.667" Height="215.333"
Left="100" Top="100">
F#方法:
member x.Window_Loaded (sender : object, eventArgs : RoutedEventArgs) = // Do stuff
答案 0 :(得分:0)
使用FsXaml.Wpf v.3.1.3时,我有......
StartupUri="MainWindow.xaml"
...在我的app.xaml文件中。我将其删除并在我的App.fs文件中使用它来打开MainWindow.xaml ...
[<STAThread>]
[<EntryPoint>]
let main argv =
Wpf.installSynchronizationContext ()
Views.MainWindow()
|> App().Run
...与WpfMvvmAgent演示相匹配。这解决了我上面的XamlParseException。