Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public override string ToString()
new GalleryPageFactory(() => new ScrollViewControlPage(), "ScrollView Feature Matrix"),
new GalleryPageFactory(() => new GraphicsViewControlPage(), "GraphicsView Feature Matrix"),
new GalleryPageFactory(() => new EditorControlPage(), "Editor Feature Matrix"),
new GalleryPageFactory(() => new ContentViewControlPage(), "ContentView Feature Matrix")
};

public CorePageView(Page rootPage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public class ContentViewControlPage : NavigationPage
{
public ContentViewControlPage()
{
var vm = new ContentViewViewModel();
var mainPage = new ContentViewControlMainPage(vm);
PushAsync(mainPage);
}
}
public class ContentViewControlMainPage : ContentPage
{
private ContentView _dynamicContentHost;
private ContentViewViewModel _viewModel;


public ContentViewControlMainPage(ContentViewViewModel viewModel)
{
_viewModel = viewModel;
BindingContext = viewModel;

this.SetBinding(ContentPage.BackgroundColorProperty, nameof(ContentViewViewModel.BackgroundColor));
this.SetBinding(ContentPage.IsEnabledProperty, nameof(ContentViewViewModel.IsEnabled));
this.SetBinding(ContentPage.IsVisibleProperty, nameof(ContentViewViewModel.IsVisible));
this.SetBinding(ContentPage.FlowDirectionProperty, nameof(ContentViewViewModel.FlowDirection));
_dynamicContentHost = new ContentView();

UpdateContentViews();

var mainLayout = new VerticalStackLayout
{
Spacing = 2,
Padding = new Thickness(5),
Children =
{
_dynamicContentHost,
}
};

Content = mainLayout;

ToolbarItems.Add(new ToolbarItem
{
Text = "Options",
Command = new Command(async () =>
{
_viewModel.HeightRequest = -1;
_viewModel.WidthRequest = -1;
_viewModel.BackgroundColor = Colors.LightGray;
_viewModel.IsEnabled = true;
_viewModel.IsVisible = true;
_viewModel.FlowDirection = FlowDirection.LeftToRight;
_viewModel.HasShadow = false;
_viewModel.DefaultLabelText = "This is Default Page";
_viewModel.ContentLabel = "Default";
_viewModel.ControlTemplateKeyFirst = "DefaultFirstTemplate";
_viewModel.ControlTemplateKeySecond = "DefaultSecondTemplate";
_viewModel.IconImageSource = "dotnet_bot.png";
_viewModel.CardTitle = "First ContentView Page";
_viewModel.CardColor = Colors.SkyBlue;

UpdateContentViews();
await Navigation.PushAsync(new ContentViewOptionsPage(_viewModel));
})
});

viewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(ContentViewViewModel.ContentLabel)
|| e.PropertyName == nameof(ContentViewViewModel.ControlTemplateKeyFirst)
|| e.PropertyName == nameof(ContentViewViewModel.ControlTemplateKeySecond))
{
UpdateContentViews();
}
};
}
private void UpdateContentViews()
{
if (_viewModel.ContentLabel == "FirstCustomPage")
{
var firstView = new ContentViewFirstCustomPage
{
CardDescription = "Use ContentViewPage as the content, binding all card properties to the ViewModel",
IconBackgroundColor = Colors.LightGray,
BorderColor = Colors.Pink
};
firstView.SetBinding(ContentViewFirstCustomPage.CardTitleProperty, nameof(ContentViewViewModel.CardTitle));
firstView.SetBinding(ContentViewFirstCustomPage.IconImageSourceProperty, nameof(ContentViewViewModel.IconImageSource));
firstView.SetBinding(ContentViewFirstCustomPage.CardColorProperty, nameof(ContentViewViewModel.CardColor));
firstView.BindingContext = _viewModel;
if (!string.IsNullOrEmpty(_viewModel.ControlTemplateKeyFirst) && firstView.Resources.ContainsKey(_viewModel.ControlTemplateKeyFirst))
firstView.ControlTemplate = (ControlTemplate)firstView.Resources[_viewModel.ControlTemplateKeyFirst];
_dynamicContentHost.Content = firstView;
}
else if (_viewModel.ContentLabel == "SecondCustomPage")
{
var secondView = new ContentViewSecondCustomPage
{
SecondCustomViewTitle = "Second Custom Title",
SecondCustomViewDescription = "This is the description for the second custom view.",
SecondCustomViewText = "This is the SECOND custom view",
FrameBackgroundColor = Colors.LightGray
};
secondView.BindingContext = _viewModel;
if (!string.IsNullOrEmpty(_viewModel.ControlTemplateKeySecond) && secondView.Resources.ContainsKey(_viewModel.ControlTemplateKeySecond))
secondView.ControlTemplate = (ControlTemplate)secondView.Resources[_viewModel.ControlTemplateKeySecond];
_dynamicContentHost.Content = secondView;
}
else
{
var defaultLabel = new Label
{
FontSize = 18
};
defaultLabel.SetBinding(Label.TextProperty, nameof(ContentViewViewModel.DefaultLabelText));
var button = new Button
{
Text = "Change Text",
AutomationId = "TextChangedButton"
};
button.Clicked += (s, e) =>
{
_viewModel.DefaultLabelText = "Text Changed after Button Click!";
};
var stack = new StackLayout
{
Spacing = 12,
Padding = new Thickness(20),
BackgroundColor = Colors.LightYellow,
Children = { defaultLabel, button }
};
stack.BindingContext = _viewModel;
_dynamicContentHost.Content = stack;
_dynamicContentHost.SetBinding(ContentView.HeightRequestProperty, nameof(ContentViewViewModel.HeightRequest));
_dynamicContentHost.SetBinding(ContentView.WidthRequestProperty, nameof(ContentViewViewModel.WidthRequest));
_dynamicContentHost.SetBinding(ContentView.ShadowProperty, nameof(ContentViewViewModel.ContentViewShadow));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.ContentViewFirstCustomPage">
<ContentView.Resources>
<ResourceDictionary>
<ControlTemplate x:Key="DefaultFirstTemplate">
<Border BackgroundColor="{TemplateBinding CardColor}"
Stroke="{TemplateBinding BorderColor}"
StrokeThickness="10"
HeightRequest="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Row="0"
Grid.Column="0"
Stroke="{TemplateBinding BorderColor}"
BackgroundColor="{TemplateBinding IconBackgroundColor}"
WidthRequest="100"
HeightRequest="100">
<Image Source="{TemplateBinding IconImageSource}"
Aspect="AspectFill"/>
</Border>
<Label Grid.Row="0"
Grid.Column="1"
Text="{TemplateBinding CardTitle}"
FontAttributes="Bold"
HeightRequest="100"/>
<Label Grid.Row="1"
Grid.Column="1"
Text="{TemplateBinding CardDescription}"/>
<HorizontalStackLayout Grid.Row="3"
Grid.Column="1">
<Button Text="Change Text"
AutomationId="ChangeTextButton"
Clicked="OnChangeTextButtonClicked"/>
<Label Text="{TemplateBinding NewTextChanged}"
FontAttributes="Bold"/>
</HorizontalStackLayout>
</Grid>
</Border>
</ControlTemplate>
<ControlTemplate x:Key="AlternateCardTemplate">
<Border BackgroundColor="LightGreen"
Stroke="DarkGreen"
StrokeThickness="10"
HeightRequest="250">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Row="0"
Grid.Column="0"
Stroke="DarkGreen"
BackgroundColor="LightGreen"
WidthRequest="100"
HeightRequest="100">
<Image Source="{TemplateBinding IconImageSource}"
Aspect="AspectFill"/>
</Border>
<Label Grid.Row="0"
Grid.Column="1"
Text="{TemplateBinding CardTitle}"
FontAttributes="Bold"
VerticalOptions="Center"
HeightRequest="100"/>
<Label Grid.Row="1"
Grid.Column="1"
Text="{TemplateBinding CardDescription}"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<Label Grid.Row="2"
Grid.Column="1"
Text="First Control Template Applied"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<HorizontalStackLayout Grid.Row="3"
Grid.Column="1">
<Button Text="Change Text"
Clicked="OnChangeTextButtonClicked"/>
<Label Text="{TemplateBinding NewTextChanged}"
FontAttributes="Bold"/>
</HorizontalStackLayout>
</Grid>
</Border>
</ControlTemplate>
</ResourceDictionary>
</ContentView.Resources>
<ContentView.ControlTemplate>
<StaticResource Key="DefaultFirstTemplate"/>
</ContentView.ControlTemplate>
</ContentView>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public partial class ContentViewFirstCustomPage : ContentView
{
public static readonly BindableProperty CardTitleProperty =
BindableProperty.Create(nameof(CardTitle), typeof(string), typeof(ContentViewFirstCustomPage), string.Empty);

public static readonly BindableProperty CardDescriptionProperty =
BindableProperty.Create(nameof(CardDescription), typeof(string), typeof(ContentViewFirstCustomPage), string.Empty);

public static readonly BindableProperty IconImageSourceProperty =
BindableProperty.Create(nameof(IconImageSource), typeof(ImageSource), typeof(ContentViewFirstCustomPage), default(ImageSource));

public static readonly BindableProperty IconBackgroundColorProperty =
BindableProperty.Create(nameof(IconBackgroundColor), typeof(Color), typeof(ContentViewFirstCustomPage), Colors.Gray);

public static readonly BindableProperty BorderColorProperty =
BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(ContentViewFirstCustomPage), Colors.Black);

public static readonly BindableProperty CardColorProperty =
BindableProperty.Create(nameof(CardColor), typeof(Color), typeof(ContentViewFirstCustomPage), Colors.White);

public static readonly BindableProperty NewTextChangedProperty =
BindableProperty.Create(nameof(NewTextChanged), typeof(string), typeof(ContentViewFirstCustomPage), "Failed");

public string NewTextChanged
{
get => (string)GetValue(NewTextChangedProperty);
set => SetValue(NewTextChangedProperty, value);
}

public string CardTitle
{
get => (string)GetValue(CardTitleProperty);
set => SetValue(CardTitleProperty, value);
}

public string CardDescription
{
get => (string)GetValue(CardDescriptionProperty);
set => SetValue(CardDescriptionProperty, value);
}

public ImageSource IconImageSource
{
get => (ImageSource)GetValue(IconImageSourceProperty);
set => SetValue(IconImageSourceProperty, value);
}

public Color IconBackgroundColor
{
get => (Color)GetValue(IconBackgroundColorProperty);
set => SetValue(IconBackgroundColorProperty, value);
}

public Color BorderColor
{
get => (Color)GetValue(BorderColorProperty);
set => SetValue(BorderColorProperty, value);
}

public Color CardColor
{
get => (Color)GetValue(CardColorProperty);
set => SetValue(CardColorProperty, value);
}

private void OnChangeTextButtonClicked(object sender, EventArgs e)
{
NewTextChanged = "Success";
}

public ContentViewFirstCustomPage()
{
InitializeComponent();
}
}
Loading
Loading