C
C#15mo ago
r2d25551

❔ Bind derived class and base class to CollectionView and Picker

I am trying to bind a derived class to a Picker, and the base class to a CollectionView. Should this work? My picker is always empty:
<CollectionView ItemsSource="{Binding MyData}"
<Picker Grid.Row="1" Title="Language" ItemsSource="{Binding Languages}" ItemDisplayBinding="{Binding Name}" . . . />
<CollectionView ItemsSource="{Binding MyData}"
<Picker Grid.Row="1" Title="Language" ItemsSource="{Binding Languages}" ItemDisplayBinding="{Binding Name}" . . . />
The base class bindings are fine. . . but my picker is having trouble.
5 Replies
Azrael
Azrael15mo ago
How does your class look like?
r2d25551
r2d25551OP15mo ago
My base class is:
public partial class ProfilesViewModel : ObservableObject
{
public Profile Profile { get; set; }

public int SelectionCount { get; set; } = 0;

public ObservableCollection<Profile> Profiles { get; private set; }

public IList<Profile> EmptyProfiles { get; private set; }

public ObservableCollection<object> SelectedProfiles { get; set; }

public string SelectedProfileMessage { get; private set; }

protected App app = null;

public ProfilesViewModel()
{
app = (App)Application.Current;
Profiles = new ObservableCollection<Profile>(app.AppSettings.GetProfiles());

Profile = Profiles.FirstOrDefault();

SelectedProfiles = new ObservableCollection<object>();
}
}
public partial class ProfilesViewModel : ObservableObject
{
public Profile Profile { get; set; }

public int SelectionCount { get; set; } = 0;

public ObservableCollection<Profile> Profiles { get; private set; }

public IList<Profile> EmptyProfiles { get; private set; }

public ObservableCollection<object> SelectedProfiles { get; set; }

public string SelectedProfileMessage { get; private set; }

protected App app = null;

public ProfilesViewModel()
{
app = (App)Application.Current;
Profiles = new ObservableCollection<Profile>(app.AppSettings.GetProfiles());

Profile = Profiles.FirstOrDefault();

SelectedProfiles = new ObservableCollection<object>();
}
}
Derived class is minimal:
public class LanguageViewModel : ProfilesViewModel
{
public ObservableCollection<Microsoft.Maui.Media.Locale> Languages { get; private set; }

public LanguageViewModel(App app) : base()
{
Languages = new ObservableCollection<Locale>(app.LanguageManager.locales);
}
}
public class LanguageViewModel : ProfilesViewModel
{
public ObservableCollection<Microsoft.Maui.Media.Locale> Languages { get; private set; }

public LanguageViewModel(App app) : base()
{
Languages = new ObservableCollection<Locale>(app.LanguageManager.locales);
}
}
r2d25551
r2d25551OP15mo ago
And XAML (sorry):




r2d25551
r2d25551OP15mo ago
The Picker works fine if it is placed above the CollecitonView. It works as expected. But when added to the CollectionView nothing shows
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server