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