Skip to content

Commit

Permalink
Set up example
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed May 14, 2021
1 parent e6c2b58 commit 8348156
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 67 deletions.
114 changes: 48 additions & 66 deletions src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public MainPage(IServiceProvider services, MainPageViewModel viewModel)
_services = services;
BindingContext = _viewModel = viewModel;

//SetupMauiLayout();
SetupVisibilityTest();
SetupMauiLayout();

NavigationPage.SetHasNavigationBar(this, false);

//SetupCompatibilityLayout();
//SetupVisibilityTest();
}

public class VisibilityLabel : Label
public class VisibilityLabel : Label, IFrameworkElement
{
private Visibility _visibility;

Expand All @@ -49,7 +49,7 @@ public void SetVisibility(Visibility visibility)
Handler?.UpdateValue(nameof(Visibility));
}

public override Visibility Visibility
Visibility IFrameworkElement.Visibility
{
get
{
Expand All @@ -58,68 +58,6 @@ public override Visibility Visibility
}
}

void SetupVisibilityTest()
{
var layout = new VerticalStackLayout() { BackgroundColor = Colors.BurlyWood };
//var layout = new Microsoft.Maui.Controls.Layout2.GridLayout() { BackgroundColor = Colors.AntiqueWhite };

var button1 = new Button { Text = "Controls", Margin = new Thickness(0, 40) };

var button2 = new Button { Text = "MAUI" };

var controlsLabel = new Label { Text = "Controls Label" };
controlsLabel.IsVisible = true;

var alwaysVisible = new Label { Text = "Always visible" };

var mauiLabel = new VisibilityLabel() { Text = "Core Label" };

button1.Clicked += (sender, args) => {
controlsLabel.IsVisible = !controlsLabel.IsVisible;
};

button2.Clicked += (sender, args) =>
{
switch (mauiLabel.Visibility)
{
case Visibility.Visible:
mauiLabel.SetVisibility(Visibility.Hidden);
break;
case Visibility.Hidden:
mauiLabel.SetVisibility(Visibility.Collapsed);
break;
case Visibility.Collapsed:
mauiLabel.SetVisibility(Visibility.Visible);
break;
}
};

//layout.AddRowDefinition(new RowDefinition() { Height = GridLength.Auto });
//layout.AddRowDefinition(new RowDefinition() { Height = GridLength.Auto });
//layout.AddRowDefinition(new RowDefinition() { Height = GridLength.Auto });
//layout.AddRowDefinition(new RowDefinition() { Height = GridLength.Auto });
//layout.AddRowDefinition(new RowDefinition() { Height = GridLength.Auto });

//layout.AddColumnDefinition(new ColumnDefinition { Width = new GridLength(300) });

layout.Add(button1);
//layout.SetRow(button1, 0);

layout.Add(button2);
//layout.SetRow(button2, 1);

layout.Add(controlsLabel);
//layout.SetRow(controlsLabel, 2);

layout.Add(mauiLabel);
//layout.SetRow(mauiLabel, 3);

layout.Add(alwaysVisible);
//layout.SetRow(alwaysVisible, 4);

Content = layout;
}

const string loremIpsum =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"Quisque ut dolor metus. Duis vel iaculis mauris, sit amet finibus mi. " +
Expand Down Expand Up @@ -532,5 +470,49 @@ void AddTextResizeDemo(Microsoft.Maui.ILayout layout)
layout.Add(widthAndHeightTestLabel);
layout.Add(explicitWidthTestLabel);
}

void SetupVisibilityTest()
{
var layout = new VerticalStackLayout() { BackgroundColor = Colors.BurlyWood };

var button1 = new Button { Text = "Controls", Margin = new Thickness(0, 40) };

var button2 = new Button { Text = "MAUI" };

var controlsLabel = new Label { Text = "Controls Label" };
controlsLabel.IsVisible = true;

var alwaysVisible = new Label { Text = "Always visible" };

var mauiLabel = new VisibilityLabel() { Text = "Core Label" };

button1.Clicked += (sender, args) => {
controlsLabel.IsVisible = !controlsLabel.IsVisible;
};

button2.Clicked += (sender, args) =>
{
switch ((mauiLabel as IFrameworkElement).Visibility)
{
case Visibility.Visible:
mauiLabel.SetVisibility(Visibility.Hidden);
break;
case Visibility.Hidden:
mauiLabel.SetVisibility(Visibility.Collapsed);
break;
case Visibility.Collapsed:
mauiLabel.SetVisibility(Visibility.Visible);
break;
}
};

layout.Add(button1);
layout.Add(button2);
layout.Add(controlsLabel);
layout.Add(mauiLabel);
layout.Add(alwaysVisible);

Content = layout;
}
}
}
2 changes: 1 addition & 1 deletion src/Controls/src/Core/HandlerImpl/VisualElement.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected virtual Size MeasureOverride(double widthConstraint, double heightCons
Primitives.LayoutAlignment IFrameworkElement.HorizontalLayoutAlignment => default;
Primitives.LayoutAlignment IFrameworkElement.VerticalLayoutAlignment => default;

public virtual Visibility Visibility => IsVisible.ToVisibility();
Visibility IFrameworkElement.Visibility => IsVisible.ToVisibility();

Semantics IFrameworkElement.Semantics
{
Expand Down

0 comments on commit 8348156

Please sign in to comment.