Skip to content

Commit 41c8e1a

Browse files
Merge pull request #2 from SyncfusionExamples/852373_UpdateReadme
852373_Updated Readme file
2 parents 87b6eae + 7c196db commit 41c8e1a

File tree

1 file changed

+129
-1
lines changed

1 file changed

+129
-1
lines changed

README.md

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,130 @@
1-
# Load-PageContent-into-SfTabView
1+
# Load PageContent into SfTabView
22
This article explains about how to load content of page into Xamarin.Forms SfTabView
3+
## Creating the project
4+
Create a new BlankApp (Xamarin.Forms.Portable) application in Xamarin Studio or Visual Studio for Xamarin.Forms.
5+
6+
## Adding SfTabView in Xamarin.Forms
7+
Add the required assembly references to the PCL and renderer projects as discussed in the Assembly deployment section.
8+
9+
Import the control namespace as shown in the following code.
10+
11+
**[XAML]**
12+
```
13+
xmlns:tabView="clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms"
14+
```
15+
**[C#]**
16+
```
17+
using Syncfusion.XForms.TabView;
18+
```
19+
Set the control to content in ContentPage.
20+
21+
**[XAML]**
22+
```
23+
<ContentPage.Content>
24+
<tabView:SfTabView/>
25+
</ContentPage.Content>
26+
```
27+
**[C#]**
28+
```
29+
public MainPage()
30+
{
31+
InitializeComponent();
32+
tabView = new SfTabView();
33+
this.Content = tabView;
34+
}
35+
```
36+
# Adding ListView in SfTabView
37+
38+
Create a view model class with the ContactsInfo collection property, which is initialized with required number of data objects.
39+
40+
**[C#]**
41+
```
42+
public class ContactInfo
43+
{
44+
public string Name { get; set; }
45+
public long Number { get; set; }
46+
}
47+
48+
public class ContactsViewModel : INotifyPropertyChanged
49+
{
50+
private ObservableCollection<ContactInfo> contactList;
51+
public event PropertyChangedEventHandler PropertyChanged;
52+
53+
public ObservableCollection<ContactInfo> ContactList
54+
{
55+
get { return contactList; }
56+
set { contactList = value; }
57+
}
58+
public ContactsViewModel()
59+
{
60+
ContactList = new ObservableCollection<ContactInfo>();
61+
ContactList.Add(new ContactInfo{Name = "Aaron",Number = 7363750});
62+
ContactList.Add(new ContactInfo { Name = "Adam", Number = 7323250 });
63+
ContactList.Add(new ContactInfo { Name = "Adrian", Number = 7239121 });
64+
ContactList.Add(new ContactInfo { Name = "Alwin", Number = 2329823 });
65+
ContactList.Add(new ContactInfo { Name = "Alex", Number = 8013481 });
66+
ContactList.Add(new ContactInfo { Name = "Alexander", Number = 7872329 });
67+
ContactList.Add(new ContactInfo { Name = "Barry", Number = 7317750 });
68+
}
69+
}
70+
```
71+
72+
# Binding data to ListView
73+
Bind the items source of the ListView, and set the required appearance in its ItemTemplate property in which the list view can be hosted within the content region of tab item.
74+
75+
**[XAML]**
76+
```
77+
<ContentPage.Content>
78+
<tabView:SfTabView BackgroundColor="#f6f6f6" x:Name="tabView">
79+
<tabView:SfTabItem Title="{Binding Title1}">
80+
<tabView:SfTabItem.Content>
81+
<Grid BackgroundColor="White" x:Name="AllContactsGrid" >
82+
<ListView x:Name="ContactListView"
83+
ItemsSource="{Binding ContactList}"
84+
RowHeight="75">
85+
<ListView.BindingContext>
86+
<local:ContactsViewModel />
87+
</ListView.BindingContext>
88+
<ListView.ItemTemplate>
89+
<DataTemplate>
90+
<ViewCell>
91+
<StackLayout Orientation="Vertical" Margin="30,0,0,0">
92+
<Label
93+
Text="{Binding Name}"
94+
FontSize="24" />
95+
<Label
96+
Text="{Binding Number}"
97+
FontSize="20"
98+
TextColor="LightSlateGray" />
99+
</StackLayout>
100+
</ViewCell>
101+
</DataTemplate>
102+
</ListView.ItemTemplate>
103+
</ListView>
104+
</Grid>
105+
</tabView:SfTabItem.Content>
106+
</tabView:SfTabItem>
107+
<tabView:SfTabItem Title="Favorites">
108+
<tabView:SfTabItem.Content>
109+
<Grid BackgroundColor="Green" x:Name="FavouritesGrid" />
110+
</tabView:SfTabItem.Content>
111+
</tabView:SfTabItem>
112+
<tabView:SfTabItem Title="Contacts">
113+
<tabView:SfTabItem.Content>
114+
<Grid BackgroundColor="Blue" x:Name="ContactsGrid" />
115+
</tabView:SfTabItem.Content>
116+
</tabView:SfTabItem>
117+
</tabView:SfTabView>
118+
</ContentPage.Content>
119+
```
120+
## How to run this application?
121+
122+
To run this application, you need to first clone the Load-PageContent-into-SfTabView repository and then open it in Visual Studio 2022. Now, simply build and run your project to view the output.
123+
124+
## <a name="troubleshooting"></a>Troubleshooting ##
125+
### Path too long exception
126+
If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.
127+
128+
## License
129+
130+
Syncfusion has no liability for any damage or consequence that may arise by using or viewing the samples. The samples are for demonstrative purposes, and if you choose to use or access the samples, you agree to not hold Syncfusion liable, in any form, for any damage that is related to use, for accessing, or viewing the samples. By accessing, viewing, or seeing the samples, you acknowledge and agree Syncfusion’s samples will not allow you seek injunctive relief in any form for any claim related to the sample. If you do not agree to this, do not view, access, utilize, or otherwise do anything with Syncfusion’s samples.

0 commit comments

Comments
 (0)