I tried this with String (hstring) combo items and everything worked fine. Now I try to use structure and... trying to fill ComboBox and select one of them. ComboBox is filled ok, but no item is selected. I'd like to select them by Locale. What I do wrong? :)
Parts of source files here. IDL file:
[default_interface]
runtimeclass LanguageOpt
{
LanguageOpt();
String Native;
String Locale;
};
[default_interface]
runtimeclass Settings : Microsoft.UI.Xaml.Controls.Page, Microsoft.UI.Xaml.Data.INotifyPropertyChanged
{
Settings();
// UI languages
Windows.Foundation.Collections.IObservableVector<LanguageOpt> Languages{ get; };
LanguageOpt CurrentLang;
}
Some code (.h):
struct Settings : SettingsT<Settings>
{
Windows::Foundation::Collections::IObservableVector<LanguageOpt> Languages();
LanguageOpt CurrentLang();
void CurrentLang(LanguageOpt const& value);
private:
LanguageOpt m_CurrentLang;
Windows::Foundation::Collections::IObservableVector<LanguageOpt> m_Languages;
};
.cpp file
Settings::Settings()
{
m_Languages = winrt::single_threaded_observable_vector<LanguageOpt>();
... // filling m_Languages
// set current language
m_CurrentLang.Locale(L"en-US");
m_CurrentLang.Native(L"English");
}
XAML:
<ComboBox x:Name="LanguageCombo"
ItemsSource="{x:Bind Languages}"
SelectedValuePath="Locale"
SelectedValue="{x:Bind CurrentLang, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:LanguageOpt">
<TextBlock Text="{x:Bind Native}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ComboBox>
When I try to check what's selected (after changing selection in running app) by calling CurrentLang(), I get the same value set in Settings constructor despite TwoWays mode. It looks like binding is not established :)
I tried this with String (hstring) combo items and everything worked fine. Now I try to use structure and... trying to fill ComboBox and select one of them. ComboBox is filled ok, but no item is selected. I'd like to select them by Locale. What I do wrong? :)
Parts of source files here. IDL file:
[default_interface]
runtimeclass LanguageOpt
{
LanguageOpt();
String Native;
String Locale;
};
[default_interface]
runtimeclass Settings : Microsoft.UI.Xaml.Controls.Page, Microsoft.UI.Xaml.Data.INotifyPropertyChanged
{
Settings();
// UI languages
Windows.Foundation.Collections.IObservableVector<LanguageOpt> Languages{ get; };
LanguageOpt CurrentLang;
}
Some code (.h):
struct Settings : SettingsT<Settings>
{
Windows::Foundation::Collections::IObservableVector<LanguageOpt> Languages();
LanguageOpt CurrentLang();
void CurrentLang(LanguageOpt const& value);
private:
LanguageOpt m_CurrentLang;
Windows::Foundation::Collections::IObservableVector<LanguageOpt> m_Languages;
};
.cpp file
Settings::Settings()
{
m_Languages = winrt::single_threaded_observable_vector<LanguageOpt>();
... // filling m_Languages
// set current language
m_CurrentLang.Locale(L"en-US");
m_CurrentLang.Native(L"English");
}
XAML:
<ComboBox x:Name="LanguageCombo"
ItemsSource="{x:Bind Languages}"
SelectedValuePath="Locale"
SelectedValue="{x:Bind CurrentLang, Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:LanguageOpt">
<TextBlock Text="{x:Bind Native}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ComboBox>
When I try to check what's selected (after changing selection in running app) by calling CurrentLang(), I get the same value set in Settings constructor despite TwoWays mode. It looks like binding is not established :)
Share Improve this question asked Mar 17 at 12:52 CyberDemonCyberDemon 13 bronze badges 2 |1 Answer
Reset to default 0Finally I've found the solution.
Changes in IDL file:
- runtimeclass LanguageOpt must be declared with BindableAttribute
[Windows.UI.Xaml.Data.Bindable]
runtimeclass LanguageOpt
{
LanguageOpt();
String Native {get;};
String Locale {get;};
};
- LanguageOpt CurrentLang must be changed to
IInspectable CurrentLang;
I hope this will help to anybody who will encounter the same problem :)
SelectedItem="{x:Bind CurrentLang, Mode=TwoWay}"
without setting SelectedValuePath. – Clemens Commented Mar 17 at 14:39