13

XAML デザイナーでをバインドしGridViewましたが、エンティティが型に変換されており、エンティティ プロパティにアクセスできないため、プロパティが不明です。正常に実行され、エラーは発生しませんが、デザイナーはそれをエラーとして表示します。コレクションにバインドすると、プロパティに問題なくアクセスできますICollectionViewCollectionViewObject

エンティティがプロパティを持つ例で、それらを に配置し、Personそこからビューを取得し、それをバインドして、列ヘッダープロパティを設定しようとすると、デザイナーはそれをエラーとして表示しますstring NameObservableCollection<Person>GridView.ItemsSourceDataMemberBinding.FirstName

タイプ オブジェクトのデータ コンテキストでプロパティ 'FirstName' を解決できません

それはバグですか、それともResharperが私にいたずらをしているのですか

サンプルコード:

public class Person 
{
    public string FirstName{
       get { return _firstName; }
       set { SetPropertyValue("FirstName", ref _firstName, value); }
    }
}
public class DataService 
{
    public IDataSource DataContext { get; set; }
    public ICollectionView PersonCollection{ get; set; }

    public DataService()
    {
        DataContext = new DataSource();
        //QueryableCollectionView is from Telerik 
        //but if i use any other CollectionView same thing
        //DataContext Persons is an ObservableCollection<Person> Persons
        PersonCollection = new QueryableCollectionView(DataContext.Persons);
    }
}

<telerik:RadGridView x:Name="ParentGrid" 
    ItemsSource="{Binding DataService.PersonCollection}"
    AutoGenerateColumns="False">
    <telerik:RadGridView.Columns >
        <telerik:GridViewDataColumn Header="{lex:Loc Key=FirstName}"  
            DataMemberBinding="{Binding FirstName}"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

ここに画像の説明を入力

4

3 に答える 3

8

Resharper が XAML ビューで表示している警告は、コントロールのデザインタイム ビューがデータ コンテキストの型を認識していないためです。ad:DesignInstance を使用してバインディングを支援できます。

以下を追加します (アセンブリ/名前空間/バインド ターゲット名を適切に置き換えます)

<UserControl x:Class="MyNamespace.UserControl1"
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"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lcl="clr‐namespace:MyAssembly"
d:DataContext="{d:DesignInstance Type=lcl:ViewModel}">
于 2014-06-29T18:22:04.170 に答える