4
嘗試從C#遷移到F#(我第一次使用MVC而不是MVVM,所以我的術語可能會關閉),但最終我無法設置我的WPF \ XAML DataContext,所以我可以綁定我的UI。愚蠢的F# WPF錯誤 - 「即使智能感知看到它名稱空間'xyz''中不存在名稱abc'」
我有以下簡單的WPF:
<UserControl x:Class="epic.Sandbox.Controls.FieldController"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:epic.Sandbox.Controls"
xmlns:Views="clr-namespace:epic.View;assembly=epic.Core"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<Views:TextFieldModel />
</UserControl.DataContext>
<Grid>
</Grid>
</UserControl>
和下面的F#:
namespace epic.View
open System
open FSharp.Desktop.UI
[<AbstractClass>]
type public FieldModelBase() =
inherit Model()
let mutable fieldCaption: string = null
let mutable fieldValue: System.Object = null
[<DerivedProperty>]
member this.Caption with public get() = sprintf "%s" fieldCaption and set value = fieldCaption <- sprintf "%s" value; this.NotifyPropertyChanged "Caption"
[<DerivedProperty>]
member this.Value with public get() = fieldValue and set value = fieldValue <- value; this.NotifyPropertyChanged "Value"
type public TextFieldModel() =
inherit FieldModelBase()
XAML編輯器的智能感知看到我的課,因爲你可以從下面的截圖中看到:
任何想法我做錯了什麼?
對於MVVM,你可以試試FSharp.ViewModule。 – s952163
手動刪除你的bin內容並重建代碼庫後,你還會得到這個嗎?另外,請確認epic.View是在需要的地方明確聲明的。 – Terrance
謝謝@認爲是它。尷尬,並感激.. – TaterJuice