質問

WPFアプリケーションにMVPパターンを使用しています。 ObjectDataproviderを、自分の見解のコンストラクターに設定したプレゼンターオブジェクトに設定したいと思います。その後、プレゼンターのプロパティにコントロールにバインドしたいと思います。

私はこのようにObjectDataProviderを定義しました:

<Window.Resources>
    <ObjectDataProvider x:Key="pres" ObjectType="{x:Type local:MyPresenter}"/>
</Window.Resources>
<Grid DataContext="{Binding pres}" >
     <ComboBox Name="_fileTypes" SelectedValuePath="Key" DisplayMemberPath="Value" 
               ItemsSource="{Binding Path=FileType}"/>
</Grid>

public partial class MyView : Window
{
    public ViewPresenter MyPresenter { get; set; }
    public Dictionary<int, string> FileNames { get; private set; }

    public MyView()
    {
        InitializeComponent();
        this.ViewPresenter = new MyPresenter(this, (IService)ObjectFactory.GetInstance<IService>());
        this.FileType = GetFileTypes();
    }
}

残念ながら、ObjectDataproviderは正しく設定されていないようです。コンボボックスは空で、これを検査すると、Resources ["pres"

{System.Windows.Data.ObjectDataProvider}
base {System.Windows.Data.DataSourceProvider}: {System.Windows.Data.ObjectDataProvider}
ConstructorParameters: Count = 0
IsAsynchronous: false
MethodName: null
MethodParameters: Count = 0
ObjectInstance: null
ObjectType: {Name = "MyPresenter" FullName = "Test.Presenters.MyPresenter"}

私の見解のmypresenterプロパティを使用するために、ObjectDataproviderを正しく定義するにはどうすればよいですか?

役に立ちましたか?

解決

通常、ビューのデータコンテキストを設定します。

publivmyView(){this.datacontext = new Model(); }

クラスモデル{public int someproperty {get; set;}}

これにより、このようなモデルのプロパティにバインドできます。

他のヒント

リソースにバインドするには、次の構文を使用する必要があります。

<Grid DataContext="{Binding {StaticResource Presenter}}" />
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top