Skip to content

Commit 45bace3

Browse files
committed
Finished the country data templates.
1 parent b9d594b commit 45bace3

7 files changed

Lines changed: 73 additions & 50 deletions

File tree

sample/CountryData.Sample.MAUI/CountryData.Sample.MAUI/AppShell.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Shell.FlyoutBehavior="Disabled">
88

99
<ShellContent
10-
Title="Hello, World!"
10+
Title="Here is Country Data"
1111
ContentTemplate="{DataTemplate local:MainPage}"
1212
Route="MainPage" />
1313

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<ReactiveUI />
3+
</Weavers>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
8+
</xs:all>
9+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
10+
<xs:annotation>
11+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
12+
</xs:annotation>
13+
</xs:attribute>
14+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
15+
<xs:annotation>
16+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
17+
</xs:annotation>
18+
</xs:attribute>
19+
<xs:attribute name="GenerateXsd" type="xs:boolean">
20+
<xs:annotation>
21+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
22+
</xs:annotation>
23+
</xs:attribute>
24+
</xs:complexType>
25+
</xs:element>
26+
</xs:schema>
Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,31 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4-
x:Class="CountryData.Sample.MAUI.MainPage">
4+
x:Class="CountryData.Sample.MAUI.MainPage"
5+
xmlns:viewmodels="clr-namespace:CountryData.Sample.MAUI.ViewModels"
6+
x:DataType="{x:Type viewmodels:MainViewModel}"
7+
xmlns:country="clr-namespace:CountryData.Standard;assembly=CountryData.Standard">
58

6-
<ScrollView>
7-
<VerticalStackLayout Spacing="25" Padding="30">
9+
<CollectionView ItemsSource="{Binding Countries}">
10+
<CollectionView.ItemTemplate>
11+
<DataTemplate x:DataType="{x:Type country:Country}">
12+
<ContentView>
13+
<Grid ColumnDefinitions="Auto,30,*"
14+
Margin="5"
15+
ColumnSpacing="5">
16+
<Label Text="{Binding CountryFlag}"
17+
FontSize="Large"/>
818

9-
<Label
10-
Text="Hello, World!"
11-
SemanticProperties.HeadingLevel="Level1"
12-
FontSize="32"
13-
HorizontalOptions="Center" />
19+
<Label Grid.Column="1"
20+
Text="{Binding CountryShortCode}"/>
1421

15-
<Label
16-
Text="Welcome to .NET Multi-platform App UI"
17-
SemanticProperties.HeadingLevel="Level1"
18-
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
19-
FontSize="18"
20-
HorizontalOptions="Center" />
21-
22-
<Label
23-
Text="Current count: 0"
24-
FontSize="18"
25-
FontAttributes="Bold"
26-
x:Name="CounterLabel"
27-
HorizontalOptions="Center" />
28-
29-
<Button
30-
Text="Click me"
31-
FontAttributes="Bold"
32-
SemanticProperties.Hint="Counts the number of times you click"
33-
Clicked="OnCounterClicked"
34-
HorizontalOptions="Center" />
35-
36-
<Image
37-
Source="dotnet_bot.png"
38-
SemanticProperties.Description="Cute dot net bot waving hi to you!"
39-
WidthRequest="250"
40-
HeightRequest="310"
41-
HorizontalOptions="Center" />
42-
43-
</VerticalStackLayout>
44-
</ScrollView>
22+
<Label Grid.Column="2"
23+
HorizontalTextAlignment="Start"
24+
HorizontalOptions="FillAndExpand"
25+
Text="{Binding CountryName}"/>
26+
</Grid>
27+
</ContentView>
28+
</DataTemplate>
29+
</CollectionView.ItemTemplate>
30+
</CollectionView>
4531
</ContentPage>
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
namespace CountryData.Sample.MAUI;
1+
using CountryData.Sample.MAUI.ViewModels;
2+
3+
namespace CountryData.Sample.MAUI;
24

35
public partial class MainPage : ContentPage
46
{
57
int count = 0;
68

7-
public MainPage()
9+
public MainPage(MainViewModel mainViewModel)
810
{
911
InitializeComponent();
12+
BindingContext = mainViewModel;
1013
}
1114

12-
private void OnCounterClicked(object sender, EventArgs e)
13-
{
14-
count++;
15-
CounterLabel.Text = $"Current count: {count}";
15+
//private void OnCounterClicked(object sender, EventArgs e)
16+
//{
17+
// count++;
18+
// CounterLabel.Text = $"Current count: {count}";
1619

17-
SemanticScreenReader.Announce(CounterLabel.Text);
18-
}
20+
// SemanticScreenReader.Announce(CounterLabel.Text);
21+
//}
1922
}
2023

sample/CountryData.Sample.MAUI/CountryData.Sample.MAUI/MauiProgram.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace CountryData.Sample.MAUI;
1+
using CountryData.Sample.MAUI.ViewModels;
2+
3+
namespace CountryData.Sample.MAUI;
24

35
public static class MauiProgram
46
{
@@ -13,6 +15,9 @@ public static MauiApp CreateMauiApp()
1315
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
1416
});
1517

18+
builder.Services.AddTransient<MainPage>();
19+
builder.Services.AddTransient<MainViewModel>();
20+
1621
return builder.Build();
1722
}
1823
}

sample/CountryData.Sample.MAUI/CountryData.Sample.MAUI/ViewModels/MainViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace CountryData.Sample.MAUI.ViewModels
1313
public class MainViewModel : ReactiveObject
1414
{
1515
[Reactive]
16-
ObservableCollection<Country> Countries { get; set; }
16+
public ObservableCollection<Country> Countries { get; set; }
1717

1818
public MainViewModel()
1919
{
20-
Countries = new ObservableCollection<Country>();
20+
Countries = new ObservableCollection<Country>(new CountryHelper().GetCountryData());
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)