question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ComboBox does not dynamically change text

See original GitHub issue

Hello! I’m using translation files for my application. I denote the translated string as follows: <v:String x:Key="Key">(Here is the translation)</v:String>. Also, changing the application language changes dynamically, that is, you do not have to restart.

If I change the language, the text remains in the settings. But when I open the ComboBox, everything is fine. nNRN2wyQlB

I also noticed that if you use DynamicResource for pages, the first selected item will not be displayed at all. We have to use StaticResource for the first element. This works with the normal style too, I’ve tested. image

Avalonia version: 0.10.0-preview2 This problem was encountered in previous versions.

Please tell me what this might be related to?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timuniecommented, Feb 3, 2023

Okay, at least I found a workaround.

  1. Add a new class which provides the requested resource. We will listen to resource changes inside.
    public class ResourceProvider : ReactiveObject
    {
        public ResourceProvider(string key)
        {
            App.Current.GetResourceObservable(key).BindTo(this, x => x.Value);
        }

        [Reactive]
        public string Value { get; set; }  
    }
  1. In our MainViewModel we add a list of Items:
    public MainWindowViewModel()
    {
        _languageManager = new(new CultureInfo("ru-RU"));

        foreach (var lang in _languageManager.Languages)
            LangItems.Add(new LangItem(lang));

        _selectedLangIndex = _languageManager.Languages.IndexOf(_languageManager.CurrentLanguage);

+        Items.Add(new ResourceProvider("VaueFirst"));
+        Items.Add(new ResourceProvider("VaueSecond"));
    }

+  public List<ResourceProvider> Items { get; } = new();
  1. and now change the ComboBox like this
  <ComboBox SelectedIndex="0" 
+           Items="{Binding Items}">
+     <ComboBox.ItemTemplate>
+         <DataTemplate>
+             <TextBlock Text="{Binding Value}" />
+         </DataTemplate>
+     </ComboBox.ItemTemplate>
</ComboBox>

Result: image

Hope it helps a bit. I still think the issue needs to be solved one day.

0reactions
izaksuilovcommented, Feb 3, 2023

Anyway thanks for solution! I think it suits me so far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - WPF Textblock text does not change dynamically on ...
My problem is that when I select a item in the combobox, textblock text does not change, it always have the default value....
Read more >
Add new item dynamically in Combo box
Solved: I want the user be able to enter a free form text in Combobox and if it is not in the list,...
Read more >
Display full text of selected dynamic combobox in textbox
Hello again folks, I have a quick question. I currently have a multipage userform that populates dynamic comboboxes within a frame on a ......
Read more >
Dynamic text from a drop-down list does not update...
When you 're editing the dropdown fields select the empty line entry and close the field properties dialogue box. The last value that...
Read more >
Populate an ActiveX combo box with dynamic data from a ...
Hello everyone, I have this issue that I've been struguling with for 2 days. I have an activex combo box called EmpresaCB which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found