Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1365
GalleryItemSettings options not showing in GalleryTool
posted

Using WPF 22.2 and .NET 4.8.

I am trying to set up a GalleryTool using MVVM and it's working so far except the text alignment is always centered instead of left justified. I'm setting the GalleryItemSettings but the text alignment settings are not being respected.

I'm using Brian Lagunas' approach to binding the items (and groups):

public class GalleryToolAttachedProperties
	{
		#region Items Property
		public static readonly DependencyProperty ItemsProperty = DependencyProperty.RegisterAttached("Items",
			typeof(IEnumerable<GalleryItem>),
			typeof(GalleryToolAttachedProperties),
			new UIPropertyMetadata(null, new PropertyChangedCallback(OnItemsPropertyChanged)));

		public static IEnumerable<GalleryItem> GetItems(DependencyObject obj)
		{
			return (IEnumerable<GalleryItem>) obj.GetValue(ItemsProperty);
		}

		public static void SetItems(DependencyObject obj, IEnumerable<GalleryItem> value)
		{
			obj.SetValue(ItemsProperty, value);
		}

		private static void OnItemsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			GalleryTool tool = obj as GalleryTool ?? throw new ArgumentException("Items can only be set on a GalleryTool.");
			if (e.NewValue is IEnumerable<GalleryItem> items)
			{
				tool.Items.AddRange(items);
			}
		}
		#endregion

		#region Groups Property
		public static readonly DependencyProperty GroupsProperty = DependencyProperty.RegisterAttached("Groups",
			typeof(IEnumerable<GalleryItemGroup>),
			typeof(GalleryToolAttachedProperties),
			new UIPropertyMetadata(null, new PropertyChangedCallback(OnGroupsPropertyChanged)));

		public static IEnumerable<GalleryItemGroup> GetGroups(DependencyObject obj)
		{
			return (IEnumerable<GalleryItemGroup>) obj.GetValue(GroupsProperty);
		}

		public static void SetGroups(DependencyObject obj, IEnumerable<GalleryItemGroup> value)
		{
			obj.SetValue(GroupsProperty, value);
		}

		private static void OnGroupsPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			GalleryTool tool = obj as GalleryTool ?? throw new ArgumentException("Groups can only be set on a GalleryTool.");
			if (e.NewValue is IEnumerable<GalleryItemGroup> groups)
			{
				foreach (GalleryItemGroup group in groups)
				{
					tool.Groups.Add(group);
				}
			}
		}
		#endregion
	}

								<igRibbon:MenuTool x:Name="_addRunMenuTool"
																	 Margin="10,0,0,0"
																	 Caption="Add"
																	 ToolTip="Adds an analysis run"
																	 ShouldDisplayGalleryPreview="False"
																	 ButtonType="DropDown"
																	 LargeImage="{StaticResource AddIcon}"
																	 SmallImage="{StaticResource AddIcon}"
																	 igRibbon:RibbonGroup.MaximumSize="ImageAndTextLarge"
																	 IsEnabled="{Binding SelectedAnalysisRun.IsEditingLabel, Converter={StaticResource InverseBooleanConverter}}">
									<igRibbon:GalleryTool ssiInfragistics:GalleryToolAttachedProperties.Items="{Binding NewAnalysisRunOptions}"
																				ssiInfragistics:GalleryToolAttachedProperties.Groups="{Binding NewAnalysisRunGroups}">
										<igRibbon:GalleryTool.ItemSettings>
											<igRibbon:GalleryItemSettings TextDisplayMode="Always"
																										HorizontalTextAlignment="Left"
																										VerticalTextAlignment="Center"
																										TextPlacement="LeftOfImage"
																										SelectionDisplayMode="HighlightEntireItem" />
										</igRibbon:GalleryTool.ItemSettings>
										<i:Interaction.Triggers>
											<i:EventTrigger EventName="ItemSelected">
												<prism:InvokeCommandAction Command="{Binding ElementName=_addRunMenuTool, Path=DataContext.NewAnalysisRunCommand}" />
											</i:EventTrigger>
										</i:Interaction.Triggers>
									</igRibbon:GalleryTool>
								</igRibbon:MenuTool>

		private ObservableCollection<GalleryItem> _newAnalysisRunOptions;
		public ObservableCollection<GalleryItem> NewAnalysisRunOptions
		{
			get => _newAnalysisRunOptions;
			private set => SetProperty(ref _newAnalysisRunOptions, value);
		}

		private ObservableCollection<GalleryItemGroup> _newAnalysisRunGroups;
		public ObservableCollection<GalleryItemGroup> NewAnalysisRunGroups
		{
			get => _newAnalysisRunGroups;
			private set => SetProperty(ref _newAnalysisRunGroups, value);
		}

The EventTrigger is also not working, so if you have any idea on what's going on with either issue I'd really appreciate it.