Reputation: 744
for some need I have to add a grid into my content page. I tried this :
public HomePage()
{
Grid = new Grid
{
RowDefinitions = new RowDefinitionCollection() { new RowDefinition() { Height = GridLength.Star } },
ColumnDefinitions = new ColumnDefinitionCollection() { new ColumnDefinition() { Width = GridLength.Star } },
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
ColumnSpacing = 0,
RowSpacing = 0,
};
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == ContentProperty.PropertyName)
{
if (!IsGridSet)
{
Grid.Children.Add(Content);
IsGridSet = true;
Content = Grid;
}
}
}
It seems to work because the page is shown correctly, but none control works, Button, entry everything seems to be deactivate or unreachable, like if one another transparent component was placed on foreground.
Upvotes: 1
Views: 281
Reputation: 744
I finally get a solution :smile:
public HomePage()
{
Grid = new Grid
{
RowDefinitions = new RowDefinitionCollection() { new RowDefinition() { Height = GridLength.Star } },
ColumnDefinitions = new ColumnDefinitionCollection() { new ColumnDefinition() { Width = GridLength.Star } },
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
ColumnSpacing = 0,
RowSpacing = 0,
};
}
public static BindableProperty HomeContentProperty = BindableProperty.Create(nameof(HomeContent), typeof(Xamarin.Forms.View), typeof(HomePage));
public Xamarin.Forms.View HomeContent
{
get => (Xamarin.Forms.View)GetValue(HomeContentProperty);
set => SetValue(HomeContentProperty, value);
}
Grid Grid { get; set; }
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (HomeContentProperty.PropertyName == propertyName)
{
if (HomeContent != null)
{
Grid.Children.Add(HomeContent);
Content = Grid;
}
}
}
And I can show my alert from anywhere I want.
Upvotes: 0