F # view model mapping

From the XAML editor, I can set the namespace in the Viewmodel contained in the C # project

namespace ViewModelDB
{
    public class DependencyViewModel : IViewModelDB
    {
        public string Message { get; set; }
    }
}

And in my 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>

Then the "Message" binding is recognized.

When I point to the F # namespace with a similar environment

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

Then I lose the binding message recognition

<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>

Am I doing something wrong? This is due to the fact that Message is an implementation of the IDependencyViewModel interface and an explicit implementation of interfaces in F #, which is good, but is there any way around this here?

+5
source share
1 answer

I don’t think there is a better solution than the one that we discussed in the comments, so I am turning this into a longer answer.

, , - , - F # , WPF Message, . - ( ):

type DependencyViewModel () = 
    member val Message = "" with get, set
    interface IDependencyViewModel with 
        member x.Message with get() = x.Message and set(v) = x.Message <- v

, , , #, F #. , F # ( ) ( ), , .

( ), DataContext, , , , .

+6

All Articles