veri bağlama, benXAML düzenleyicinizden bir F # ViewModel
<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>
bağlayıcı "Message" bir C# projesi
namespace ViewModelDB
{
public class DependencyViewModel : IViewModelDB
{
public string Message { get; set; }
}
}
yılında Ve benim xaml içerdiği ViewModel ad ayarlayabilirsiniz tanıdı.
Ben o zaman bağlayıcı Mesaj tanınmasını gevşek
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
benzer seçmen bir F # ad işaret zaman
<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>
Yanlış mı yapıyorum? Bunun nedeni, Message IDependencyViewModel arabiriminin bir uygulaması ve F # içindeki arabirimlerin açık bir şekilde uygulanmasıdır, bu iyi bir şeydir, fakat buralarda buralarda çalışmak için var mıdır?
Dediğiniz gibi - bunun nedeni muhtemelen arabirim uygulamasının açık olmasıdır. Her zamanki çözüm, yalnızca 'Message' isminin kendisine bir özellik eklemektir (ve arayüz uygulaması buna referans verebilir). –
(C# yönergelerini takip etmenin F # + WPF için bu işe yaramayacağını düşünüyorum, bu yüzden kodu yazmanın daha iyi bir yolunu bulabilirsin. Örneğin, görünüm modeli arabirimine sahip olmalısın?) –
Sanırım bir özellik eklemek en hafif yaklaşımdır. Ve muhtemelen bir arayüze sahip olmak çok fazla. DI için rağmen bu nokta oldukça. – nicolas