private static void OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { GalleryItemGroup galleryItemGroup = d as GalleryItemGroup; if (e.NewValue == null) { return; } //Clear any existing items that were owned by this if (galleryItemGroup.ItemKeys.Count > 0) { foreach (var key in galleryItemGroup.ItemKeys) { if (galleryItemGroup.GalleryTool.Items.ContainsKey(key)) { galleryItemGroup.GalleryTool.Items.Remove(galleryItemGroup.GalleryTool.Items[key]); } } } galleryItemGroup.ItemKeys.Clear(); //Get the image converter that will provide image paths var imageConverter = galleryItemGroup.GetValue(GalleryItemGroupProperties.ImageConverterProperty) as IValueConverter; foreach (var item in (IEnumerable)e.NewValue) { var galleryItem = new GalleryItem { Key = item.ToString(), Text = item.ToString(), }; if (imageConverter != null) { galleryItem.Image = new BitmapImage(new Uri((string)imageConverter.Convert(item, typeof(string), null, null), UriKind.RelativeOrAbsolute)); } galleryItemGroup.GalleryTool.Items.Add(galleryItem); galleryItemGroup.ItemKeys.Add(item.ToString()); } //Check if GalleryToolProperties.SelectedItemKey was set var selectedItem = galleryItemGroup.GalleryTool.GetValue(GalleryToolProperties.SelectedItemKeyProperty); { if (selectedItem != null) { galleryItemGroup.GalleryTool.SetValue(GalleryToolProperties.SelectedItemKeyProperty, null); galleryItemGroup.GalleryTool.SetValue(GalleryToolProperties.SelectedItemKeyProperty, selectedItem); } } }
private static GalleryItemSelectedCommandBehavior GetOrCreateBehavior(GalleryItemGroup menuItem) { GalleryItemSelectedCommandBehavior behavior = menuItem.GetValue(SelectedCommandBehaviorProperty) as GalleryItemSelectedCommandBehavior; if (behavior == null) { behavior = new GalleryItemSelectedCommandBehavior(menuItem); menuItem.SetValue(SelectedCommandBehaviorProperty, behavior); } return(behavior); }
public static object GetImageConverter(GalleryItemGroup source) { return((object)source.GetValue(ImageConverterProperty)); }
public static object GetDataSource(GalleryItemGroup source) { return((object)source.GetValue(DataSourceProperty)); }
public static object GetGroupKeys(GalleryItemGroup source) { return((object)source.GetValue(GroupKeysProperty)); }
public static object GetCommandParameter(GalleryItemGroup menuItem) { return(menuItem.GetValue(CommandParameterProperty)); }
public static ICommand GetCommand(GalleryItemGroup menuItem) { return(menuItem.GetValue(CommandProperty) as ICommand); }