Solved! Go to Solution.
ItemsControl attachmentListControl = null; public override void OnApplyTemplate() { base.OnApplyTemplate(); attachmentListControl = GetTemplateChild("AttachmentList") as ItemsControl; RegisterForNotification("ItemsSource", this.attachmentListControl, new PropertyChangedCallback(ItemsSourceChanged)); } public void ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { System.Collections.ObjectModel.ObservableCollection<AttachmentInfo> attachmentInfoList = e.NewValue as System.Collections.ObjectModel.ObservableCollection<AttachmentInfo>; attachmentListControl.ItemsSource = attachmentInfoList.Where(x => x.Name.Contains(".pdf")); //or better check content type } public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) { Binding b = new Binding(propertyName) { Source = element }; var prop = System.Windows.DependencyProperty.RegisterAttached("ListenAttached" + propertyName, typeof(object), typeof(UserControl), new System.Windows.PropertyMetadata(callback)); element.SetBinding(prop, b); }
ItemsControl attachmentListControl = null; public override void OnApplyTemplate() { base.OnApplyTemplate(); attachmentListControl = GetTemplateChild("AttachmentList") as ItemsControl; RegisterForNotification("ItemsSource", this.attachmentListControl, new PropertyChangedCallback(ItemsSourceChanged)); } public void ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { System.Collections.ObjectModel.ObservableCollection<AttachmentInfo> attachmentInfoList = e.NewValue as System.Collections.ObjectModel.ObservableCollection<AttachmentInfo>; attachmentListControl.ItemsSource = attachmentInfoList.Where(x => x.Name.Contains(".pdf")); //or better check content type } public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) { Binding b = new Binding(propertyName) { Source = element }; var prop = System.Windows.DependencyProperty.RegisterAttached("ListenAttached" + propertyName, typeof(object), typeof(UserControl), new System.Windows.PropertyMetadata(callback)); element.SetBinding(prop, b); }
public class FileVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string fileName = System.Convert.ToString(value); // Current file name string extension = System.Convert.ToString(parameter).ToLower(); // Visible extension, e.g. ".pdf" if (System.IO.Path.GetExtension(fileName).ToLower() == extension) { return Visibility.Visible; } else { return Visibility.Collapsed; } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
<DataTemplate x:Key="AttachmentEditorTemplate"> <Grid Margin="3" Visibility="{Binding Name, Converter={StaticResource FileVisibilityConverter}, ConverterParameter='.pdf'}"> ...
A good idea is to make a new control inherits from Attachment Editor control then override onApplytemplate method to get the ItemsControl object.
After that you can listen on ItemsSource property changed via DependencyProperty.RegisterAttached Method.
Check this post for more information.
ItemsControl attachmentListControl = null; public override void OnApplyTemplate() { base.OnApplyTemplate(); attachmentListControl = GetTemplateChild("AttachmentList") as ItemsControl; RegisterForNotification("ItemsSource", this.attachmentListControl, new PropertyChangedCallback(ItemsSourceChanged)); } public void ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { System.Collections.ObjectModel.ObservableCollection<AttachmentInfo> attachmentInfoList = e.NewValue as System.Collections.ObjectModel.ObservableCollection<AttachmentInfo>; attachmentListControl.ItemsSource = attachmentInfoList.Where(x => x.Name.Contains(".pdf")); //or better check content type } public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback) { Binding b = new Binding(propertyName) { Source = element }; var prop = System.Windows.DependencyProperty.RegisterAttached("ListenAttached" + propertyName, typeof(object), typeof(UserControl), new System.Windows.PropertyMetadata(callback)); element.SetBinding(prop, b); }
you can also add another property for your filter to be more dynamic.
Hope this helps.
Regards,
From what I can understand this approach would work, too. How do you know the ESRI AttachmentEditor contains an ItemsControl named "AttachmentList" (and that it is an ItemsControl)?