, , , , .
CollectionViewSource.Source , CollectionViewSource / , ComboBox . , , :
public sealed class BindingBridge : DependencyObject
{
#region BridgeInstance property
public static BindingBridge GetBridgeInstance(DependencyObject obj)
{
Contract.Requires(obj != null);
return (BindingBridge)obj.GetValue(BridgeInstanceProperty);
}
public static void SetBridgeInstance(DependencyObject obj, BindingBridge value)
{
Contract.Requires(obj != null);
obj.SetValue(BridgeInstanceProperty, value);
}
public static readonly DependencyProperty BridgeInstanceProperty =
DependencyProperty.RegisterAttached("BridgeInstance", typeof(BindingBridge), typeof(BindingBridge),
new PropertyMetadata(OnBridgeInstancePropertyChanged));
#endregion BridgeInstance property
#region SourceElement property
public FrameworkElement SourceElement
{
get { return (FrameworkElement)GetValue(SourceElementProperty); }
private set { SetValue(SourceElementPropertyKey, value); }
}
private static readonly DependencyPropertyKey SourceElementPropertyKey =
DependencyProperty.RegisterReadOnly("SourceElement", typeof(FrameworkElement), typeof(BindingBridge), new PropertyMetadata(null));
public static readonly DependencyProperty SourceElementProperty;
#endregion SourceElement property
static BindingBridge()
{
SourceElementProperty = SourceElementPropertyKey.DependencyProperty;
}
private static void OnBridgeInstancePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var sourceElement = (FrameworkElement)d;
var bridge = (BindingBridge)e.NewValue;
bridge.SourceElement = sourceElement;
}
}
( ):
<ItemsControl
infrastructure:BindingBridge.BridgeInstance="{StaticResource ImagesBindingBridge}">
<ItemsControl.ItemsSource>
<Binding>
<Binding.Source>
<CollectionViewSource
Source="{Binding SourceElement.DataContext.Images, Source={StaticResource ImagesBindingBridge}, Mode=OneWay}">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription PropertyName="Timestamp" Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Binding.Source>
</Binding>
</ItemsControl.ItemsSource>
</ItemsControl>
source
share