から利用可能なすべてのメモを一覧表示するListBoxコントロールを備えたメモアプリケーションがありますObservableCollection<Note> Notes
。class Note
次のような属性があります
String Title;
bool Has_Reminder;
DateTime Reminder_Date;
私が欲しいのは、がtrueのReminder_Date
場合にのみ、を表示するTextBlock要素が表示されることです。Has_Reminder
しかし、カスタムコントロールのNoteListItemからこの属性にアクセスする方法がわかりません。そのthis.DataContext
属性はですnull
が、コントロールは、ListBoxItemsSourceによって渡されたNoteのバインドされた属性を適切に表示します。どうすればそれを達成できますか?
ご協力いただきありがとうございます。
コンストラクターで属性を読み取ろうとしましたが、機能しませんでした。
public NoteListItem()
{
InitializeComponent();
Note this_note = LayoutRoot.DataContext as Note; // turns out, this_note is null
if (!this_note.Has_Reminder)
Reminder_Info.Visibility = System.Windows.Visibility.Collapsed;
}
NoteListItemコントロール
<Grid x:Name="LayoutRoot" >
<TextBlock x:Name="Title" Text="{Binding Title}" />
<TextBlock x:Name="Reminder_Date" Text="{Binding Reminder_Date}" />
</Grid>
NoteListコントロール:
<ListBox x:Name="NoteListBox" ItemsSource="{Binding Notes}" >
<ListBox.ItemTemplate>
<DataTemplate>
<local:NoteListItem />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>