Using RadTabView in an MVVM app

1 Answer 401 Views
TabView
Kori
Top achievements
Rank 2
Kori asked on 16 Dec 2022, 03:47 PM

Is there a way to use `RadTabView` in an MVVM and handle navigation properly? Right now, `RadTabView` takes a View which makes it hard to change using Page-based content.

We have an implementation using TabbedPage but the issue is that the bar itself is not customizable (that I'm aware of) so I'd like to use `RadTabView` as a replacement if possible.

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 19 Dec 2022, 08:17 PM

Hi Kori,

Indeed, as you've seen TabView is not a ContentPage base object and cannot host other ContentPages. Rather RadTabView is a ContentView based object that is intended to be on a single ContentPage and navigate in between views.

Ultimately, TabView  it isn't designed to replace TabbedPage (or Shell's interpretation of TabbedPage). To simplify it as much as possible, the suffix of the component names tells you what they handle: TabView and TabbedPage

.NET MAUI Live MVVM & DI Demo

That being said, Ican still provide you with a little guidance. My demo on using RadTabView with IoC and DI => https://github.com/LanceMcCarthy/CustomMauiExamples#TabViewItems-with-dependency-injection might be helpful. There you will see how you can use DI to inject what you need at runtime for the specific views.

If you need to define the views in the view model, then you will need to redesign the main view model code in order to keep a centralized list of RadTabViewItem objects that are bound to the TabView's ItemsSource (for example: ObservableCollection<RadTabViewItem> Tabs). We do not have a .NET MAUI topic on the subject, but here is an older XF forum post where I answer with the code example of the concept.

That might be able to give you a head start, but I imagine you would need to redesign your entire infrastructure built for TabbedPage to meet the needs of an MVVM navigated TabView. there's just no 1:1 comparison of TabbedPage ContentPage management and RadTabView item ContentView management

Regards,
Lance | Manager Technical Support
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TabView
Asked by
Kori
Top achievements
Rank 2
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or