-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate that ContentView works adding samples in the Gallery (#1674)
- Loading branch information
1 parent
b865406
commit ff78dcb
Showing
7 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/Controls/samples/Controls.Sample/Controls/CardView/CardView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ContentView | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Controls.CardView"> | ||
<Frame | ||
x:Name="Card" | ||
BackgroundColor="{Binding CardColor}" | ||
BorderColor="{Binding BorderColor}" | ||
CornerRadius="5" | ||
HasShadow="True" | ||
Padding="8" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center" | ||
Margin="0, 12, 0, 0"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="75" /> | ||
<RowDefinition Height="4" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="75" /> | ||
<ColumnDefinition Width="200" /> | ||
</Grid.ColumnDefinitions> | ||
<Frame | ||
IsClippedToBounds="True" | ||
BorderColor="{Binding BorderColor, FallbackValue='Black'}" | ||
BackgroundColor="{Binding IconBackgroundColor, FallbackValue='Gray'}" | ||
CornerRadius="38" | ||
HeightRequest="60" | ||
WidthRequest="60" | ||
HorizontalOptions="Center" | ||
HasShadow="False" | ||
VerticalOptions="Center"> | ||
<Image | ||
Source="{Binding IconImageSource}" | ||
Margin="-20" | ||
WidthRequest="100" | ||
HeightRequest="100" | ||
Aspect="AspectFill" /> | ||
</Frame> | ||
<Label | ||
Grid.Column="1" | ||
Text="{Binding CardTitle, FallbackValue='Card Title'}" | ||
FontAttributes="Bold" | ||
FontSize="Large" | ||
VerticalTextAlignment="Center" | ||
HorizontalTextAlignment="Start" /> | ||
<BoxView | ||
Grid.Row="1" | ||
Grid.ColumnSpan="2" | ||
BackgroundColor="{Binding BorderColor, FallbackValue='Black'}" | ||
HeightRequest="2" | ||
HorizontalOptions="Fill" /> | ||
<Label | ||
Grid.Row="2" | ||
Grid.ColumnSpan="2" | ||
Text="{Binding CardDescription, FallbackValue='Card description text.'}" | ||
VerticalTextAlignment="Start" | ||
VerticalOptions="Fill" | ||
HorizontalOptions="Fill" /> | ||
</Grid> | ||
</Frame> | ||
</ContentView> |
69 changes: 69 additions & 0 deletions
69
src/Controls/samples/Controls.Sample/Controls/CardView/CardView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Maui.Controls.Sample.Controls | ||
{ | ||
public partial class CardView : ContentView | ||
{ | ||
public static readonly BindableProperty CardTitleProperty = | ||
BindableProperty.Create(nameof(CardTitle), typeof(string), typeof(CardView), string.Empty); | ||
|
||
public static readonly BindableProperty CardDescriptionProperty = | ||
BindableProperty.Create(nameof(CardDescription), typeof(string), typeof(CardView), string.Empty); | ||
|
||
public static readonly BindableProperty BorderColorProperty = | ||
BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(CardView), Colors.DarkGray); | ||
|
||
public static readonly BindableProperty CardColorProperty = | ||
BindableProperty.Create(nameof(CardColor), typeof(Color), typeof(CardView), Colors.White); | ||
|
||
public static readonly BindableProperty IconImageSourceProperty = | ||
BindableProperty.Create(nameof(IconImageSource), typeof(ImageSource), typeof(CardView), default(ImageSource)); | ||
|
||
public static readonly BindableProperty IconBackgroundColorProperty = | ||
BindableProperty.Create(nameof(IconBackgroundColor), typeof(Color), typeof(CardView), Colors.LightGray); | ||
|
||
public string CardTitle | ||
{ | ||
get => (string)GetValue(CardTitleProperty); | ||
set => SetValue(CardTitleProperty, value); | ||
} | ||
|
||
public string CardDescription | ||
{ | ||
get => (string)GetValue(CardDescriptionProperty); | ||
set => SetValue(CardDescriptionProperty, value); | ||
} | ||
|
||
public Color BorderColor | ||
{ | ||
get => (Color)GetValue(BorderColorProperty); | ||
set => SetValue(BorderColorProperty, value); | ||
} | ||
|
||
public Color CardColor | ||
{ | ||
get => (Color)GetValue(CardColorProperty); | ||
set => SetValue(CardColorProperty, value); | ||
} | ||
|
||
public ImageSource IconImageSource | ||
{ | ||
get => (ImageSource)GetValue(IconImageSourceProperty); | ||
set => SetValue(IconImageSourceProperty, value); | ||
} | ||
|
||
public Color IconBackgroundColor | ||
{ | ||
get => (Color)GetValue(IconBackgroundColorProperty); | ||
set => SetValue(IconBackgroundColorProperty, value); | ||
} | ||
|
||
public CardView() | ||
{ | ||
InitializeComponent(); | ||
|
||
Card.BindingContext = this; | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Controls/samples/Controls.Sample/Pages/Layouts/ContentViewPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<views:BasePage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Pages.ContentViewPage" | ||
xmlns:controls="clr-namespace:Maui.Controls.Sample.Controls" | ||
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base" | ||
Title="ContentView"> | ||
<views:BasePage.Content> | ||
<ScrollView> | ||
<StackLayout | ||
Padding="12"> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Slavko Vlasic" | ||
CardDescription="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit dolor, convallis non interdum." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png"/> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Carolina Pena" | ||
CardDescription="Phasellus eu convallis mi. In tempus augue eu dignissim fermentum. Morbi ut lacus vitae eros lacinia." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Wade Blanks" | ||
CardDescription="Aliquam sagittis, odio lacinia fermentum dictum, mi erat scelerisque erat, quis aliquet arcu." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Colette Quint" | ||
CardDescription="In pellentesque odio eget augue elementum lobortis. Sed augue massa, rhoncus eu nisi vitae, egestas." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" /> | ||
</StackLayout> | ||
</ScrollView> | ||
</views:BasePage.Content> | ||
</views:BasePage> |
10 changes: 10 additions & 0 deletions
10
src/Controls/samples/Controls.Sample/Pages/Layouts/ContentViewPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Maui.Controls.Sample.Pages | ||
{ | ||
public partial class ContentViewPage | ||
{ | ||
public ContentViewPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/Controls/samples/Controls.Sample/Pages/Layouts/TemplatedViewPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<views:BasePage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Pages.TemplatedViewPage" | ||
xmlns:controls="clr-namespace:Maui.Controls.Sample.Controls" | ||
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base" | ||
Title="TemplatedView"> | ||
<views:BasePage.Resources> | ||
<ResourceDictionary> | ||
|
||
<ControlTemplate x:Key="CardViewCompressed"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="100" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="100" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<Image | ||
Source="{TemplateBinding IconImageSource}" | ||
BackgroundColor="{TemplateBinding IconBackgroundColor}" | ||
WidthRequest="100" | ||
HeightRequest="100" | ||
Aspect="AspectFill" | ||
HorizontalOptions="Center" | ||
VerticalOptions="Center" /> | ||
<StackLayout Grid.Column="1"> | ||
<Label | ||
Text="{TemplateBinding CardTitle}" | ||
FontAttributes="Bold" /> | ||
<Label | ||
Text="{TemplateBinding CardDescription}" /> | ||
</StackLayout> | ||
</Grid> | ||
</ControlTemplate> | ||
|
||
</ResourceDictionary> | ||
</views:BasePage.Resources> | ||
<views:BasePage.Content> | ||
<StackLayout | ||
Padding="12"> | ||
<Label | ||
Text="A standard CardView control is suitable for grid layouts:" | ||
FontAttributes="Italic" | ||
TextColor="Red" | ||
Margin="0,0,0,10" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Slavko Vlasic" | ||
CardDescription="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla elit dolor, convallis non interdum." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" /> | ||
<Label | ||
Text="A ControlTemplate overrides the standard view, creating a more compact view suitable for lists:" | ||
FontAttributes="Italic" | ||
TextColor="Red" | ||
Margin="0,0,0,10" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Carolina Pena" | ||
CardDescription="Phasellus eu convallis mi. In tempus augue eu dignissim fermentum. Morbi ut lacus vitae eros lacinia." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" | ||
ControlTemplate="{StaticResource CardViewCompressed}" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Wade Blanks" | ||
CardDescription="Aliquam sagittis, odio lacinia fermentum dictum, mi erat scelerisque erat, quis aliquet arcu." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" | ||
ControlTemplate="{StaticResource CardViewCompressed}" /> | ||
<controls:CardView | ||
BorderColor="DarkGray" | ||
CardTitle="Colette Quint" | ||
CardDescription="In pellentesque odio eget augue elementum lobortis. Sed augue massa, rhoncus eu nisi vitae, egestas." | ||
IconBackgroundColor="SlateGray" | ||
IconImageSource="dotnet_bot.png" | ||
ControlTemplate="{StaticResource CardViewCompressed}" /> | ||
</StackLayout> | ||
</views:BasePage.Content> | ||
</views:BasePage> |
10 changes: 10 additions & 0 deletions
10
src/Controls/samples/Controls.Sample/Pages/Layouts/TemplatedViewPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Maui.Controls.Sample.Pages | ||
{ | ||
public partial class TemplatedViewPage | ||
{ | ||
public TemplatedViewPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters