C# WPF project with reference to F# ViewModel

。_饼干妹妹 提交于 2019-12-11 09:29:37

问题


I have project named FSharpProject in whick there is code like this:

module FSharpProject.ViewModel

type A =
    member x.a = 1

In other project(typical wpf application writing in C#) which have reference to FSharpProject I have xaml file like this:

<UserControl x:Class="CSharpProjectView"
             x:Name="Root"
             xmlns:local="clr-namespace:CSharpProjectView"
             xmlns:data="clr-namespace:FSharpProject.ViewModel;assembly=FSharpProject"            
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...
<DataTemplate x:Key="LogDataTemplate" DataType="{data:A}">
                <TextBlock Text="{Binding a}" />                
            </DataTemplate>

But I get error that data:A type not found.


UPD: It does not work:

<UserControl x:Class="CSharpProjectView"
             x:Name="Root"
             xmlns:local="clr-namespace:CSharpProjectView"
             xmlns:data="clr-namespace:FSharpProject;assembly=FSharpProject"            
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...
<DataTemplate x:Key="LogDataTemplate" DataType="{data:ViewModel.A}">
                <TextBlock Text="{Binding a}" />                
            </DataTemplate>

回答1:


Your DataType should be simply data:A or {x:Type data:A}:

<DataTemplate x:Key="LogDataTemplate" DataType="data:A">


来源:https://stackoverflow.com/questions/13287437/c-sharp-wpf-project-with-reference-to-f-viewmodel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!