我正在为项目使用xamarin表单。这是我的代码。
在xaml页面中:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:customControls="clr-namespace:App5.CustomControls;assembly=HorizontalListView"
xmlns:local="clr-namespace:App5"
x:Class="App5.MainPage">
<ContentPage.Content>
<ListView HasUnevenRows="True" BackgroundColor="#f3f3f3" SeparatorVisibility="None" x:Name="lstdb"
WidthRequest="250" HorizontalOptions="Start">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame Grid.Row="0" Style="{StaticResource FrmDashboard}" Margin="5"
WidthRequest="200" HorizontalOptions="Start">
<StackLayout WidthRequest="250" HorizontalOptions="Start">
<Label Text="{Binding ImageName}" Style="{StaticResource LblDashboard}"></Label>
<Label Text="{Binding DashBoardName}" Style="{StaticResource LblDashboard}"></Label>
<Label Text="{Binding DashBoardNameSmall}" Style="{StaticResource LblDashboardSmall}"></Label>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
在cs页面中:
public MainPage()
{
InitializeComponent();
AddData();
}
private void AddData()
{
lst = new List<DashBoardItems>
{
new DashBoardItems {ImageName="Image1", DashBoardName="Notification Alert", DashBoardNameSmall="4 Alerts" },
new DashBoardItems {ImageName="Image2", DashBoardName="PPM WO LIST", DashBoardNameSmall="4 Items" },
new DashBoardItems {ImageName="Image3", DashBoardName="Breakdown / Emergency WO List", DashBoardNameSmall="5 Items" },
new DashBoardItems {ImageName="Image4", DashBoardName="Asset Information", DashBoardNameSmall="2 Informations" },
new DashBoardItems {ImageName="Image5", DashBoardName="Portering", DashBoardNameSmall="2 Porters" },
new DashBoardItems {ImageName="Image6", DashBoardName="Raise Breakdown", DashBoardNameSmall="" },
new DashBoardItems {ImageName="Image7", DashBoardName="Tracking Technician", DashBoardNameSmall="" },
new DashBoardItems {ImageName="Image8", DashBoardName="Request Portering", DashBoardNameSmall="" },
};
lstdb.ItemsSource = lst.ToList();
}