diff --git a/src/Eto.Wpf/Forms/Controls/ComboBoxHandler.cs b/src/Eto.Wpf/Forms/Controls/ComboBoxHandler.cs index c0d7737f24..d2695959b3 100644 --- a/src/Eto.Wpf/Forms/Controls/ComboBoxHandler.cs +++ b/src/Eto.Wpf/Forms/Controls/ComboBoxHandler.cs @@ -120,6 +120,19 @@ public override Color BackgroundColor } } + public override Color TextColor + { + get => Control.TextBox?.Foreground.ToEtoColor() ?? base.TextColor; + set + { + var textBox = Control.TextBox; + if (textBox != null) + textBox.Foreground = value.ToWpfBrush(); + else + PerformOnLoad(() => TextColor = value); + } + } + public bool ReadOnly { get { return Control.IsReadOnly; } diff --git a/src/Eto.Wpf/Forms/Controls/DropDownHandler.cs b/src/Eto.Wpf/Forms/Controls/DropDownHandler.cs index 87d30c65fc..0e880513d4 100755 --- a/src/Eto.Wpf/Forms/Controls/DropDownHandler.cs +++ b/src/Eto.Wpf/Forms/Controls/DropDownHandler.cs @@ -205,18 +205,18 @@ public override Color BackgroundColor { var border = BorderControl; if (border != null) - { border.Background = value.ToWpfBrush(border.Background); - } + else + PerformOnLoad(() => BackgroundColor = value); } } - + public override Color TextColor { get { var block = Control.FindChild(); - return block != null ? block.Foreground.ToEtoColor() : base.TextColor; + return block?.Foreground.ToEtoColor() ?? base.TextColor; } set { @@ -224,7 +224,7 @@ public override Color TextColor if (block != null) block.Foreground = value.ToWpfBrush(); else - base.TextColor = value; + PerformOnLoad(() => TextColor = value); } } diff --git a/src/Eto.Wpf/Forms/WpfFrameworkElement.cs b/src/Eto.Wpf/Forms/WpfFrameworkElement.cs index 5558c832a4..61a1a589d4 100755 --- a/src/Eto.Wpf/Forms/WpfFrameworkElement.cs +++ b/src/Eto.Wpf/Forms/WpfFrameworkElement.cs @@ -94,6 +94,8 @@ class WpfFrameworkElement internal const string CustomCursor_DataKey = "Eto.CustomCursor"; internal static IWpfFrameworkElement LastDragTarget; + + internal static readonly object LoadActionList_Key = new object(); } public abstract partial class WpfFrameworkElement : WidgetHandler, Control.IHandler, IWpfFrameworkElement @@ -1053,5 +1055,27 @@ public void Print() } WpfFrameworkElementHelper.ShouldCaptureMouse = false; } + + internal bool PerformOnLoad(Action action) + { + if (Control.IsLoaded) + return false; + var actionList = Widget.Properties.Get>(WpfFrameworkElement.LoadActionList_Key); + if (actionList == null) + { + actionList = new List(); + Control.Loaded += (sender, e) => + { + for (int i = 0; i < actionList.Count; i++) + { + actionList[i](); + } + actionList.Clear(); + }; + Widget.Properties.Set(WpfFrameworkElement.LoadActionList_Key, actionList); + } + actionList.Add(action); + return true; + } } } diff --git a/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs b/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs index fbc94cf214..083fcfaba9 100644 --- a/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs +++ b/test/Eto.Test/UnitTests/Forms/Controls/ListControlTests.cs @@ -92,5 +92,26 @@ public void ChangingSelectedIndexMultipleTimesBeforeLoadShouldTriggerChanged() Assert.AreEqual(2, changed, "3.1 - Setting selected index again should trigger event again"); Assert.AreEqual(1, list.SelectedIndex, "3.2"); } + + [Test, ManualTest] + public void ColorsShouldBeSet() + { + ManualForm("Control should have blue background with yellow text", form => + { + return new TableLayout + { + Rows = { + new TableRow(new T { + BackgroundColor = Colors.Blue, + TextColor = Colors.Yellow, + DataStore = new[] { "Item 1", "Item 2", "Item 3" }, + SelectedIndex = 0 + }, null), + null + } + }; + }); + } + } }