あなたはインターフェイスフィールドに結合されていることを、WPF明示的に伝えることでインターフェイスにバインドすることができます。
(ViewModelBaseは、単にINotifyPropertyChangedインターフェイスを実装する基本クラスであることに注意してください)
public class Implementation : ViewModelBase, IInterface
{
private string textField;
public string TextField
{
get
{
return textField;
}
set
{
if (value == textField) return;
textField = value;
OnPropertyChanged();
}
}
}
public interface IInterface
{
string TextField { get; set; }
}
その後のViewModel上:
private IInterface interfaceContent;
public IInterface InterfaceContent
{
get { return interfaceContent; }
}
そして最後に、それを可能にするXAML:
<ContentControl Grid.Row="1" Grid.Column="0" Content="{Binding InterfaceContent}">
<ContentControl.ContentTemplate>
<DataTemplate DataType="{x:Type viewModels:IInterface}">
<TextBox Text="{Binding Path=(viewModels:IInterface.TextField)}"/>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
ご覧のとおり、バインディングは「IInterface」の定義を明示的に参照しています。
DataContextとInterfaceを 'IValueConverter'に渡す' DataTrigger'に基づいて 'ContentTemplate'を設定する' ContentControl'を使うのはどうですか?値がパラメータで渡された型であるかどうかをテストし、Trueが適切なDataTemplateを使用する場合は – Rachel