You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with the [SfTabView,](https://www.syncfusion.com/maui-controls/maui-tab-view) it's important to ensure that data binding is correctly set up so that the data is displayed within the tabs as expected. This article provides a guide on how to bind data to the respective fields within tab pages of the SfTabView.
1
+
When working with the [SfTabView,](https://www.syncfusion.com/maui-controls/maui-tab-view) it's important to ensure that data binding is correctly set up so that the data is displayed within the tabs as expected. This article provides a guide on how to bind data to the respective fields within tab pages of the Tab View.
2
2
3
-
**Step 1:** Create a new sample in the .NET MAUI and initialize TabView within the page with `BindingContext.`
3
+
**Step 1:** Create a new sample in the .NET MAUI and initialize Tab View within the page with `BindingContext.`
4
4
5
5
**XAML**
6
6
```
7
-
<contentpage.bindingcontext>
8
-
<local:viewmodel>
9
-
</local:viewmodel></contentpage.bindingcontext>
10
-
<tabview:sftabview items="{Binding Items}">
7
+
<ContentPage.BindingContext>
8
+
<local:ViewModel/>
9
+
</ContentPage.BindingContext>
10
+
<tabView:SfTabView Items="{Binding Items}"/>
11
11
```
12
12
13
-
**Step 2:** Create different content pages that you need to display as a `TabItem` and for each content page, set `BindingContext` from its respective ViewModel. For example,
13
+
**Step 2:** Create different content pages that you need to display as a `Tab Item` and for each content page, set `BindingContext` from its respective ViewModel. For example,
@@ -38,7 +42,7 @@ public class TabViewPage1ViewModel
38
42
}
39
43
```
40
44
41
-
Create as many content pages as you need for display within the `TabItem` and its respective view model, like above.
45
+
Create as many content pages as you need for display within the `Tab Item` and its respective view model, like above.
42
46
43
47
**Step 3:** To bind data to the tab pages, you need to set up your ViewModel to manage the data for each tab. Here's an example of how you can initialize your tab items and bind the context to each page:
44
48
@@ -48,67 +52,60 @@ Create as many content pages as you need for display within the `TabItem` and it
In this example, each `SfTabItem` is initialized with the content and header, and the `BindingContext` of the content is set to the `BindingContext` of the respective page.
105
+
In this example, each `Tab Item` is initialized with the content and header, and the `BindingContext` of the content is set to the `BindingContext` of the respective page.
102
106
103
107
Please note that the code snippets provided in this article are for illustrative purposes and may require adjustments to fit the specific requirements of your application.
If you are using the `Prism framework,` it's important to note that the SfTabView may not work as expected due to the way Prism `auto-wires` the binding context. Since the SfTabView is a `content view` control, and the content of the page is assigned to the tab item content, the page's binding context is set to null. This results in the ViewModel not being recognized when setting the page content to the tab item content. Therefore, the SfTabView may not be suitable for use with the Prism framework.
0 commit comments