/// <summary> Creates toggle buttons for given <paramref name="enumerationItems"/>, with icons read from resources by their <paramref name="resourceKeys"/>. </summary> /// <param name="panel"> The panel to add buttons into. </param> /// <param name="enumerationItems"> Enumeration items to create toggle buttons for. </param> /// <param name="resourceKeys"> Resource keys for <paramref name="enumerationItems"/>. </param> /// <param name="styleKey"> The key of the style (defined in <see cref="WpfClient"/> and referenced by <see cref="EStyleKey"/>) to apply. </param> /// <param name="horizontal"> Whether to arrange buttons in a row or in a column. </param> /// <param name="createToggleAllButton"> Whether to create the toggle-all button. </param> public void CreateToggleButtonsWithImages(Panel panel, IEnumerable <T> enumerationItems, IDictionary <T, string> resourceKeys, string styleKey, bool horizontal = true, bool createToggleAllButton = false) { if (createToggleAllButton && enumerationItems.Any()) { CreateToggleAllButton(panel, enumerationItems.First(), styleKey, horizontal); } foreach (var enumerationItem in enumerationItems) { var toggleButton = new ToggleButton { Style = this.GetStyle(styleKey), Tag = enumerationItem, Content = new Image() { Source = Application.Current.MainWindow.FindResource(resourceKeys[enumerationItem]) as ImageSource, Style = this.GetStyle(EStyleKey.Image.FlagIcon), }, }; toggleButton.Click += OnClick; toggleButton.AddToPanel(panel, horizontal); Buttons.Add(enumerationItem, toggleButton); } }