Skip to content

Commit b1ac89d

Browse files
Merge pull request #94 from atc-net/hotfix/WellKnownColorSelector-random-color
fix: WellKnownColorSelector selected the wrong
2 parents 22e4b73 + 7570ebc commit b1ac89d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sample/Atc.Wpf.Sample/SamplesWpfTheming/InputSelector/WellKnownColorSelectorView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
<atc:WellKnownColorSelector DropDownFirstItemType="PleaseSelect" UseOnlyBasicColors="True" />
3737

38+
<atc:WellKnownColorSelector SelectedKey="LightBlue" />
39+
3840
</atc:UniformSpacingPanel>
3941
<atc:UniformSpacingPanel
4042
Grid.Column="2"

src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ private void PopulateData(
171171

172172
Items.AddRange(list.OrderBy(x => x.DisplayName, StringComparer.Ordinal));
173173

174+
UpdateTranslationForSelectedItem();
175+
174176
if (setSelected)
175177
{
176178
if (string.IsNullOrEmpty(SelectedKey))
@@ -192,8 +194,6 @@ private IEnumerable<string> GetColorNames()
192194

193195
private void SetSelectedIndexBySelectedKey()
194196
{
195-
UpdateTranslationForSelectedItem();
196-
197197
if (CbColors.SelectedValue is null)
198198
{
199199
return;
@@ -205,10 +205,13 @@ private void SetSelectedIndexBySelectedKey()
205205
if (CbColors.Items[i] is ColorItem item &&
206206
item.Name == selectedValue)
207207
{
208-
CbColors.SelectedIndex = i;
209-
if (!processingUiCultureChanged)
208+
if (CbColors.SelectedIndex != i)
210209
{
211-
OnSelectionChanged(this, item);
210+
CbColors.SelectedIndex = i;
211+
if (!processingUiCultureChanged)
212+
{
213+
OnSelectionChanged(this, item);
214+
}
212215
}
213216

214217
break;
@@ -220,6 +223,8 @@ private void UpdateTranslationForSelectedItem()
220223
{
221224
if (CbColors.SelectedIndex != -1)
222225
{
226+
processingUiCultureChanged = true;
227+
223228
var backupIndex = CbColors.SelectedIndex;
224229
if (CbColors.Items.Count > backupIndex + 1)
225230
{
@@ -231,6 +236,8 @@ private void UpdateTranslationForSelectedItem()
231236
}
232237

233238
CbColors.SelectedIndex = backupIndex;
239+
240+
processingUiCultureChanged = false;
234241
}
235242
}
236243

0 commit comments

Comments
 (0)