1
我創建了自己的日曆。我的日曆中的每一天都是一個itemsControl,它包含一個文本塊和一個列表框,它應該包含每個日期的項目。使用ItemsControl中TextBlock的值在ListBox中過濾集合
如何使用ItemsControl中綁定文本塊的字符串值過濾集合? 文本塊與Day類的日期屬性綁定。
視圖模型
public ObservableCollection<Day> Days { get; set; }
public ObservableCollection<Scene> SceneList;
private ListCollectionView _sceneCollection;
public ListCollectionView SceneCollection
{
get
{
if (_sceneCollection == null) //important for loading the app
{
_sceneCollection = new ListCollectionView(this.SceneList);
_sceneCollection.IsLiveFiltering = true;
_sceneCollection.Filter = o =>
{
var Scene = o as Scene;
return Scene != null && Scene.Date == ////string of binded TextBlock//;
};
}
return _sceneCollection;
}
set
{
_sceneCollection = value; RaisePropertyChanged();
}
}
型號
public class Day : INotifyPropertyChanged
{
private DateTime date;
public DateTime Date
{
get { return date; }
set
{
date = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Date"));
}
}
}
的XAML
<ItemsControl ItemsSource="{Binding Days}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="6" Columns="7">
</UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Date , Converter={StaticResource DateConverter}, ConverterParameter=DAY}"/>
<ListBox ItemsSource="{Binding SceneCollection}" dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True" Height="100">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock>
<Run Text="{Binding Path=SceneNumber}"/>
<Run Text="{Binding Path=SlugLine}"/>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>