在 XAML 编辑器中,我可以将命名空间设置为 C# 项目中包含的 Viewmodel
namespace ViewModelDB
{
public class DependencyViewModel : IViewModelDB
{
public string Message { get; set; }
}
}
在我的 xaml 中
<UserControl
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:ViewModelDB="clr-namespace:ViewModelDB;assembly=ViewModelDB"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
>
<UserControl.DataContext>
<ViewModelDB:DependencyViewModel/>
</UserControl.DataContext>
<Grid>
<TextBlock Text="{Binding Message}"/>
</Grid>
</UserControl>
然后识别绑定“消息”。
当我指向类似选区的 F# 命名空间时
namespace ModuleDBGraph
open Infrastructure
open Microsoft.Practices.Prism.Regions;
open Microsoft.Practices.Unity;
type IDependencyViewModel =
inherit IViewModel
abstract Message : string with get, set
type DependencyViewModel () =
interface IDependencyViewModel with
member val Message = "" with get, set
然后我失去了对绑定消息的识别
<UserControl
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:ViewModelDB="clr-namespace:ViewModelDB;assembly=ViewModelDB"
xmlns:ViewModelDBFS="clr-namespace:ModuleDBGraph;assembly=ViewModelDBGraphFS"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
>
<UserControl.DataContext>
<ViewModelDBFS:DependencyViewModel/>
</UserControl.DataContext>
<Grid>
<TextBlock Text="{Binding Message}"/>
</Grid>
</UserControl>
难道我做错了什么 ?这是因为 Message 是接口 IDependencyViewModel 的实现和 F# 中接口的显式实现,这是一件好事,但是这里有办法解决这个问题吗?