私は文字列の観測可能なコレクションを含むオブジェクトを持っています。例えば他のオブジェクト内の文字列のObservableCollectionにDataGridをバインドします。
テイク:
public class Container
{
public ObservableCollection<string> strs; //This won't work, see edit!
.
.
.
}
XAML:サーチャーのための
<DataGrid ItemsSource="{Binding Container}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Strings" Binding="{Binding}" />
</DataGrid.Columns>
</Datagrid>
編集:いくつかは、上記のアプローチと間違ってありますが、まずあなたがアイテムのプロパティにバインドすることができます単にそれらのプロパティを参照するだけです。代わりに、それは性質(そのようだ見つけようとしての、第二
ItemsSource="{Binding Container.strs}"
、文字列の内容が文字列のプロパティではありませんので、
Binding="{Binding}"
バインド直接文字列に:この場合、長さとして)
最後に、フィールドにバインドすることはできません。プロパティのみ、違いは何ですか?
public ObservableCollection<string> strs; //This is a field
public ObservableCollection<string> strs {get; set;} //This is property
ボーナス:あなただけのSTRSをインスタンス化している場合は、一度、その後のObservableCollectionが通知されますそれが起こる以内/に変更しましたが、あなたはそれはないでしょうポインタを変更している場合は、この問題を解決する際にその結合どんなあなたはdependancyプロパティを使うことができます! 「propdp」と我々が持っていると思います。この場合には、二回タブをヒット:
public ObservableCollection<string> strs
{
get { return (ObservableCollection<string>)GetValue(strsProperty); }
set { SetValue(strsProperty, value); }
}
// Using a DependencyProperty as the backing store for strs. This enables animation, styling, binding, etc...
public static readonly DependencyProperty strsProperty =
DependencyProperty.Register("strs", typeof(ObservableCollection<string>), typeof(Container), new PropertyMetadata(""));
をVisual Studioで
は、それが形に埋めることがたくさんがあるとして、このためにスニペットで構築を使用するのが最善です