예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public static object GetImageConverter(GalleryItemGroup source)
 {
     return((object)source.GetValue(ImageConverterProperty));
 }
예제 #4
0
 public static object GetDataSource(GalleryItemGroup source)
 {
     return((object)source.GetValue(DataSourceProperty));
 }
예제 #5
0
 public static object GetGroupKeys(GalleryItemGroup source)
 {
     return((object)source.GetValue(GroupKeysProperty));
 }
예제 #6
0
 public static object GetCommandParameter(GalleryItemGroup menuItem)
 {
     return(menuItem.GetValue(CommandParameterProperty));
 }
예제 #7
0
 public static ICommand GetCommand(GalleryItemGroup menuItem)
 {
     return(menuItem.GetValue(CommandProperty) as ICommand);
 }