I'm creating a form in Xaml using Xamrin which contains absolute layout in which i'm hiding a stacklayout. but one more stacklayout just down below of hidden stacklayout but hidden stacklayout is taking up space.
What i want to do.When i did hide one stacklayout another stacklayout should take place of hidden staklayout.
Thanks for help and supports.
I've resolved the issue:
I followed this link
https://forums.xamarin.com/discussion/83632/hiding-and-showing-stacklayout in this link they said that use grid and make row height auto and it will automatically adjust the extra space of layout.
<Grid VerticalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="1" Spacing="20">
<StackLayout Margin="10,0">
<Label Text="lable 1" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 2" VerticalOptions="Center" FontSize="Small" />
</StackLayout>
<StackLayout IsVisible="{Binding IsStudent}" Margin="10,0">
<Label Text="lable3" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 4" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 5" VerticalOptions="Center" FontSize="Small" />
<Label Text="lable 6" VerticalOptions="Center" FontSize="Small" />
</StackLayout>
</StackLayout>
<StackLayout Grid.Row="2" Spacing="20" >
<local:Button
x:Name="btnSave"
Text="Submit"
VerticalOptions="End"
HorizontalOptions="FillAndExpand"
IsVisible="{Binding IsBusy, Converter={x:Static local:InverseBoolConverter.Instance}}"
AutomationId="saveButton" />
</StackLayout>
</Grid>
No need for a grid.
Set the IsVisible AND HeightRequest properties.
MyStackLayout.IsVisible = false;
MyStackLayout.HeightRequest = 0; // trigger recalc of space layout.
The change in heightrequest triggers the desired recalculations.
I've too looked into why those hidden controls are taking space and well... they ARE taking space and that's it.
You can do a simple addition and removing of labels. Something like this:
public class MyStack : StackLayout
{
Label
_label1 = new Label(),
_label2 = new Label(),
_label3 = new Label();
public void ShowLabels()
{
Children.Add(_label1);
Children.Add(_label2);
Children.Add(_label3);
}
public void HideLabels()
{
Children.Remove(_label1);
Children.Remove(_label2);
Children.Remove(_label3);
}
}
My recomendation is putting a StackLayout at the bottom of the content, in order to keep the original height of the other elements at the top.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CentroDono.Views.YOURVIEWPAGE"
Title="YOURVIEWTITLE"
x:Name="YOURPAGECONTENTNAME">
<ContentPage.Content>
<StackLayout>
<!--VISIBLE CONTENT-->
<Label Text="HELLO"/>
</StackLayout>
<StackLayout>
<Label Text="FOOTER"/>
<!--INVISIBLE CONTENT-->
<Label x:Name="_searchText" Text="Result1" IsVisible="False"/>
<Label x:Name="_searchText2" Text="Result2" IsVisible="False"/>
<Label x:Name="_searchText3" Text="Result3" IsVisible="False"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Related
I'm new to Xamarin.Forms and I'm showing a page as a modal by using:
await Navigator.PushModalAsync(modalPage);
Modal.xaml
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SandboxApp.Modal"
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.ModalPresentationStyle="FullScreen">
<ContentPage.Content>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
<Label Text="This will have some data"></Label>
<Button x:Name="closeModal" Text="Close modal" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
I understand you can set the modal size to things like:
FormSheet
FullScreen
OverFullScreen
etc
But is it possible to set the size of a modal page to a custom size?
Ideally, I'd like it to be almost full screen but with a bit of a gap around the modal so you can still see the page underneath if that makes sense?
Maybe a solution to make it work. BackgroundColor="Transparent" and work with a Frame in a Grid with a Margin
In this example i use a ListView , the Gif at the bottom to show how it looks is a bit small but you see what it looks like.
MainPage.xaml
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0,40,0,0" />
</OnPlatform>
</ContentPage.Padding>
<ContentPage.Content>
<StackLayout>
<ListView x:Name="listView" ItemSelected="OnItemSelected" />
</StackLayout>
</ContentPage.Content>
MainPage.xaml.cs
async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (listView.SelectedItem != null)
{
var detailPage = new Page1();
detailPage.BindingContext = e.SelectedItem as Contact;
listView.SelectedItem = null;
await Navigation.PushModalAsync(detailPage);
}
}
In Page1.xaml BackgroundColor="Transparent" and a Margin in the Grid
<ContentPage
x:Class="ModalStackO.Page1"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="Transparent">
<ContentPage.Content>
<Grid Margin="5,20,0,0">
<Frame BackgroundColor="#1975ce" CornerRadius="15" BorderColor="Black" />
<Frame
Margin="0,35,0,0"
BackgroundColor="White"
BorderColor="Black"
CornerRadius="5"
HeightRequest="450"
WidthRequest="280">
<StackLayout
BackgroundColor="White"
HeightRequest="350"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="280">
<StackLayout Orientation="Horizontal">
<Label
FontSize="Medium"
HorizontalOptions="FillAndExpand"
Text="Name:" />
<Label
FontAttributes="Bold"
FontSize="Medium"
Text="{Binding Name}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label
FontSize="Medium"
HorizontalOptions="FillAndExpand"
Text="Age:" />
<Label
FontAttributes="Bold"
FontSize="Medium"
Text="{Binding Age}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label
FontSize="Medium"
HorizontalOptions="FillAndExpand"
Text="Occupation:" />
<Label
FontAttributes="Bold"
FontSize="Medium"
Text="{Binding Occupation}" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label
FontSize="Medium"
HorizontalOptions="FillAndExpand"
Text="Country:" />
<Label
FontAttributes="Bold"
FontSize="Medium"
Text="{Binding Country}" />
</StackLayout>
<Button
x:Name="dismissButton"
Clicked="OnDismissButtonClicked"
Text="Dismiss" />
<Button Text="Next Page" Clicked="Button_Clicked" />
</StackLayout>
</Frame>
</Grid>
</ContentPage.Content>
</ContentPage>
Page1.xaml.cs
async void OnDismissButtonClicked(object sender, EventArgs args)
{
await Navigation.PopModalAsync();
}
private async void Button_Clicked(object sender, EventArgs e)
{
var detailPage = new Page2();
await Navigation.PushModalAsync(detailPage);
}
Then in Page2.xaml BackgroundColor="Transparent" and a bit more Margin in the Grid to show Page1 also
<ContentPage
x:Class="ModalStackO.Page2"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
BackgroundColor="Transparent">
<ContentPage.Content>
<Grid Margin="10,50,0,0">
<Frame BackgroundColor="#1975ce" CornerRadius="15" BorderColor="Black" />
<Frame
Margin="0,35,0,0"
BackgroundColor="White"
BorderColor="Black"
CornerRadius="5"
HeightRequest="450"
WidthRequest="280">
<StackLayout>
<Label
HorizontalOptions="CenterAndExpand"
Text="Welcome to Page 2"
VerticalOptions="CenterAndExpand" />
<Button Text="Back" Clicked="Button_Clicked" />
</StackLayout>
</Frame>
</Grid>
</ContentPage.Content>
Page2.xaml.cs to go back
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PopModalAsync();
}
https://github.com/rotorgames/Rg.Plugins.Popup
This is the plugin I always use to meet the UI look requirement you mentioned (padding - so I can still see the page underneath).
Instead recommended to use Popups
you have 3 options, and all are customizable in size and animation
Free
1: https://github.com/rotorgames/Rg.Plugins.Popup
Free
2: https://learn.microsoft.com/en-us/xamarin/community-toolkit/views/popup
Pay or Community Account for Free
3: https://help.syncfusion.com/xamarin/popup/getting-started
I'm trying to create a FlexLayout in Xamarin.Forms that will allow me to have the left and right columns be a variable width, and have the center column (and its contents) fill the remaining space and be centered on the screen.
Here is my current code, and here is what it's producing. Notice that "CENTER TEXT" in blue is centered within its StackLayout, but the StackLayout is not centered on the screen since the left and right columns have different widths.
Is FlexLayout a good choice for this, or should I use Grid or something else? Ideally, each column will expand to fit its content, with the center column's content being centered on the screen.
Note that the contents of each column is dynamic, so the widths of the left and right columns is also dynamic.
Thank you!
Code:
<FlexLayout x:Name="titleBar"
MinimumHeightRequest="40"
Padding="10"
JustifyContent="SpaceBetween"
AlignItems="Center"
AlignContent="Center">
<StackLayout x:Name="leftActionButton"
VerticalOptions="Center"
BackgroundColor="Red"
Orientation="Horizontal">
<Image x:Name="leftActionImg"
Margin="0, 0, 5, 0"
HeightRequest="40"
VerticalOptions="Center" />
<Label x:Name="leftActionLabel"
VerticalOptions="Center" />
</StackLayout>
<StackLayout VerticalOptions="Center"
BackgroundColor="Blue"
FlexLayout.Grow="1"
FlexLayout.Shrink="0">
<Label x:Name="title"
HorizontalTextAlignment="Center"/>
</StackLayout>
<StackLayout x:Name="rightActionButton"
BackgroundColor="Yellow"
VerticalOptions="Center"
Orientation="Horizontal">
<Label x:Name="rightActionLabel"
VerticalOptions="Center"
HorizontalOptions="End"
HorizontalTextAlignment="End" />
<Image x:Name="rightActionImg"
HeightRequest="40"
VerticalOptions="Center"
HorizontalOptions="End" />
</StackLayout>
</FlexLayout>
Results:
I was struggling with the same problem recently. So I was investing a day to find a solution. The result is disillusioning and I wouldn't call it a proper solution. I'm posting my thoughts here, because I couldn't find anything similar on the net.
I created a component which is responsible for balancing all three columns: It subscribes to width changes of the left and right column and propagates the relative difference to the center column.
The center column takes the relative difference as correction by applying a padding.
MainPage: In the Resources part you see that I'm declaring an instance of ColumnBalancer. Later I subscribe Width changes to ColumnBalancer, so ColumnBalancer gets to known when the very left and very right column (content, actually) changes. The PaddingOffset binding is retrieved from the same ColumnBalancer instance whenever the Width values have changed.
<ContentPage
x:Class="App7863.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:cb="clr-namespace:ColumnBalancing"
mc:Ignorable="d">
<ContentPage.Resources>
<ResourceDictionary>
<cb:ColumnBalancer x:Key="ColumnBalancer" x:Name="ColumnBalancer" />
</ResourceDictionary>
</ContentPage.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Header -->
<Grid
Grid.Row="0"
Padding="10"
BackgroundColor="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="39" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Navigate Back Button -->
<Label
Grid.Column="0"
Width="{Binding Source={x:Reference ColumnBalancer}, Path=ReferenceWidthLeft}"
Text="<"
FontSize="20"
BackgroundColor="Magenta"
WidthRequest="39"
HeightRequest="39"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"
HorizontalTextAlignment="Center" />
<!-- Page Title -->
<StackLayout
Grid.Column="1"
Margin="0"
Padding="{Binding Source={x:Reference ColumnBalancer}, Path=PaddingOffset}"
BackgroundColor="LightYellow"
Spacing="0">
<Label
Text="Center Title"
FontSize="20"
BackgroundColor="Magenta"
HeightRequest="39"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"
HorizontalTextAlignment="Center"
LineBreakMode="TailTruncation" />
</StackLayout>
<!-- Toolbar Items -->
<StackLayout
Grid.Column="2"
Width="{Binding Source={x:Reference ColumnBalancer}, Path=ReferenceWidthRight}"
Margin="0"
Padding="0"
BackgroundColor="LightGreen"
Orientation="Horizontal"
Spacing="6">
<Label
x:Name="ToolbarT1"
Text="T1"
FontSize="20"
BackgroundColor="Green"
WidthRequest="39"
HeightRequest="39"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"
HorizontalTextAlignment="Center"
IsVisible="False" />
<Label
x:Name="ToolbarT2"
Text="T2"
FontSize="20"
BackgroundColor="Green"
WidthRequest="39"
HeightRequest="39"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"
HorizontalTextAlignment="Center"
IsVisible="False" />
</StackLayout>
<Label
Grid.Row="2"
Grid.ColumnSpan="3"
Text="Subtitle with more info"
FontSize="20"
BackgroundColor="LightBlue"
HeightRequest="39"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
HorizontalOptions="StartAndExpand"
HorizontalTextAlignment="Start" />
</Grid>
<!-- Content -->
<Grid
Grid.Row="1"
Padding="40"
BackgroundColor="LightCoral">
<StackLayout BackgroundColor="LightBlue">
<Button Text="Toogle T1" Clicked="Button_ToogleT1" />
<Button Text="Toogle T2" Clicked="Button_ToogleT2" />
</StackLayout>
</Grid>
</Grid>
</ContentPage>
ColumnBalancer: Exposes a ReferenceWidthLeft and ReferenceWidthRight which take the Width values from the left resp. right column content. Whenever the ReferenceWidth* properties change, a new PaddingOffset is set.
public class ColumnBalancer : BindableObject
{
public static readonly BindableProperty PaddingOffsetProperty = BindableProperty.Create(
nameof(PaddingOffset),
typeof(Thickness),
typeof(ColumnBalancer),
default(Thickness),
BindingMode.OneWay);
public Thickness PaddingOffset
{
get => (Thickness)this.GetValue(PaddingOffsetProperty);
set => this.SetValue(PaddingOffsetProperty, value);
}
public static readonly BindableProperty ReferenceWidthRightProperty = BindableProperty.Create(
nameof(ReferenceWidthRight),
typeof(double),
typeof(ColumnBalancer),
default(double),
BindingMode.OneWayToSource,
null,
OnReferenceWidthRightPropertyChanged);
public double ReferenceWidthRight
{
get => (double)this.GetValue(ReferenceWidthRightProperty);
set => this.SetValue(ReferenceWidthRightProperty, value);
}
public static readonly BindableProperty ReferenceWidthLeftProperty = BindableProperty.Create(
nameof(ReferenceWidthLeft),
typeof(double),
typeof(ColumnBalancer),
default(double),
BindingMode.OneWayToSource,
null,
OnReferenceWidthLeftPropertyChanged);
public double ReferenceWidthLeft
{
get => (double)this.GetValue(ReferenceWidthLeftProperty);
set => this.SetValue(ReferenceWidthLeftProperty, value);
}
private static void OnReferenceWidthLeftPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
if (!(bindable is ColumnBalancer columnBalancer) || !(newvalue is double newLeftValue && newLeftValue >= 0))
{
return;
}
UpdatePaddingOffset(columnBalancer, newLeftValue, columnBalancer.ReferenceWidthRight);
}
private static void OnReferenceWidthRightPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
if (!(bindable is ColumnBalancer columnBalancer) || !(newvalue is double newRightValue && newRightValue >= 0))
{
return;
}
UpdatePaddingOffset(columnBalancer, columnBalancer.ReferenceWidthLeft, newRightValue);
}
private static void UpdatePaddingOffset(ColumnBalancer columnBalancer, double left, double right)
{
if (left < 0)
{
left = 0;
}
if (right < 0)
{
right = 0;
}
var relativePadding = Math.Abs(left - right);
if (right > left)
{
columnBalancer.PaddingOffset = new Thickness(relativePadding, 0, 0, 0);
}
else
{
columnBalancer.PaddingOffset = new Thickness(0, 0, relativePadding, 0);
}
}
}
I was able to get this to work by using a 2-column grid and overlaying the "center" column on top by using Grid.ColumnSpan="2".
I realize this has the potential for the content in the center to overlap the content on the left and right, but I'm OK with working around this limitation if that's the best I can do. Still welcome other, more robust suggestions, though!
<Grid x:Name="titleBar"
MinimumHeightRequest="40"
Padding="10"
HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout x:Name="leftActionButton"
VerticalOptions="Center"
Orientation="Horizontal"
HorizontalOptions="Start"
Grid.Column="0">
<Image x:Name="leftActionImg"
Margin="0, 0, 5, 0"
HeightRequest="40"
VerticalOptions="Center" />
<Label x:Name="leftActionLabel"
VerticalOptions="Center" />
</StackLayout>
<StackLayout x:Name="rightActionButton"
VerticalOptions="Center"
HorizontalOptions="End"
Orientation="Horizontal"
Grid.Column="1">
<Label x:Name="rightActionLabel"
VerticalOptions="Center"
HorizontalOptions="End"
HorizontalTextAlignment="End" />
<Image x:Name="rightActionImg"
HeightRequest="40"
VerticalOptions="Center"
HorizontalOptions="End" />
</StackLayout>
<StackLayout VerticalOptions="Center"
HorizontalOptions="CenterAndExpand"
Grid.Column="0"
Grid.ColumnSpan="2">
<Label x:Name="title"
HorizontalTextAlignment="Center"/>
</StackLayout>
</Grid>
I am creating my first Android app. I want to show TableView with some input fields and then a button to process the inputs.
I don't know why but there is extra space under TableView or the button is aligned to the bottom but it is opposite to the settings.
Can you help me fix it?
<StackLayout Orientation="Vertical" VerticalOptions="Start" Padding="20,15,20,0" Spacing="0">
<Label Text="This is TableView"></Label>
<TableView Intent="Settings" VerticalOptions="Start">
<TableRoot>
<TableSection>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="item 1"/>
<Entry></Entry>
</StackLayout>
</ViewCell>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="item 2"/>
<Entry></Entry>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
<Label Text="TableView - END"></Label>
<Button Text="My button" TextColor="DodgerBlue" VerticalOptions="Start" HorizontalOptions="Fill" Margin="40, 10, 40, 10"/>
<Frame VerticalOptions="StartAndExpand" BackgroundColor="Transparent" BorderColor="Black">
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill">
<Label Text="aaaa" HorizontalOptions="StartAndExpand"></Label>
<Label Text="value" HorizontalOptions="End"></Label>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="aaaa"></Label>
<Label Text="value"></Label>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="aaaa"></Label>
<Label Text="value"></Label>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
Your best option is to define the RowHeight for each cell, and then specify the HeightRequest for the tableview. this way you can define the space it will occupy
<TableView Margin="0" Intent="Settings" HeightRequest="120" RowHeight="60" VerticalOptions="Start">
Unfortunately, this is how Xamarin.Forms TableView/ListView works. It is not expected to have anything below it. If you need something below you can either set the height of TableView manually or to put the content in the last cell, neither thing is perfect but in any case you need to look for some workaround as this is behavior by design (it would be a bit easier if you could use the ListView instead of TableView).
As you were asking what you can do besides using a TableView, of course a Grid would be possible, please see the following example:
<Grid VerticalOptions="StartAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <!-- for the label -->
<ColumnDefinition Width="*" />
<Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="1" /> <!-- For the separator, you might have to experiment with the height -->
<RowDefinition Height="*" />
<RowDefinition Height="1" />
</Grid.RowDefinitions>
<Label Text="Item 1" />
<Entry Grid.Row="0" Grid.Column="1" />
<BoxView BackgroundColor="Black"
HeightRequest="1"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2" /> <!-- The separator -->
<Label Grid.Row="2" Grid.Column="0" Text="Item 2" />
<Entry Grid.Row="2" Grid.Column="1" />
<BoxView BackgroundColor="Black"
HeightRequest="1"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2" /> <!-- The separator -->
</Grid>
I am using BoxViews with a black background color and a HeightRequest of 1 for the separator. You might have to experiment with the color and the height to get the results you want. Values below 1 are possible and result in finer lines. In a real world example I've used .5.
Anyway, this makes the XAML way more cluttered. Grid-designs (while I am using them myself) tend to get quite unwieldy.
I am not sure if this what you are looking for but my understanding of the question tells me you are talking about the label Value being away from the rest.
if you check the code for this label :
<Label Text="value" HorizontalOptions="End"></Label>
the HorizontalOptions is set to "End" which is causing this changing it to start will fix your problem
Feel free to revert in case if I missed anything
Goodluck
I have below XAML which contains ContentView inside my main XAML.
I want to know how can I access the LabelPushNotificationPrice to change the Text?
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:SyncfusionBusyIndicator="clr-namespace:Syncfusion.SfBusyIndicator.XForms;assembly=Syncfusion.SfBusyIndicator.XForms"
x:Class="ZayedAlKhair.InitiativeDetails"
xmlns:SyncfusionPopup="clr-namespace:Syncfusion.XForms.PopupLayout;assembly=Syncfusion.SfPopupLayout.XForms"
Title="زايد الخير">
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="PushNotificationsViewTemplate">
<ContentView BackgroundColor="White" x:Name="PushNotificationsContentView">
<StackLayout Padding="15">
<Label HorizontalTextAlignment="End" Text="هذه الخدمة تمكنكم من إرسال تنبيهات الهواتف الذكية لجميع مشتركي تطبيق زايد الخير وهي أفضل خدمة لتصل مبادرتكم لآلاف المشتركين" HeightRequest="90" WidthRequest="100" />
<Label x:Name="**LabelPushNotificationPrice**" HorizontalTextAlignment="End" Text="سعر الخدمة : 499 دولار" HeightRequest="30" WidthRequest="100" />
<Label HorizontalTextAlignment="End" Text="مدة الترويج : مرة واحدة لكل مبادرة" HeightRequest="30" WidthRequest="100" />
</StackLayout>
</ContentView>
</DataTemplate>
<DataTemplate x:Key="PromoteViewTemplate">
<ContentView BackgroundColor="White" x:Name="PromoteContentView">
<StackLayout Padding="15">
<Label HorizontalTextAlignment="End" Text="هذه الخدمة ستجعل مبادرتكم مميزة باللون الأحمر ودائما في أعلى القائمة ليتمكن كل مستخدمي التطبيق من التعرف عليها والتفاعل معها" HeightRequest="90" WidthRequest="100" />
<Label HorizontalTextAlignment="End" Text="سعر الخدمة : 99 دولار" HeightRequest="30" WidthRequest="100" />
<Label HorizontalTextAlignment="End" Text="مدة التمييز : 30 يوما" HeightRequest="30" WidthRequest="100" />
</StackLayout>
</ContentView>
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Grid Padding="10" x:Name="GridInitiativeDetails">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
The preferred way is to use DataBindings, example:
<Label HorizontalTextAlignment="End" Text="{Binding LabelPushNotificationPrice}" />
This way you can seamlessly update the value of the Label bound to your ViewModel. The point is to separate UI layer from your BL layer and usually we use MVVM rather than MVC in Xamarin.Forms. The official documentation is nicely covering this topic and there are free e-books like Enterprise Application Patterns using Xamarin.Forms that I recommend to read additionally.
P.S.: Please note that setting a fixed Height & Width on UI controls may break your UX experience on screens with different sizes.
Not really sure how to properly describe my problem using correct wording as I'm new to Xamarin and Xaml.
I have a Frame with several StackLayouts within and I want to slide a specific StackLayout outside the Frame without showing it outside the Frame.
I can currently do this with:
XAML:
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
xmlns:mr="clr-namespace:MR.Gestures;assembly=MR.Gestures"
x:Class="iRemote.UI.Maps.LocationFinderMap"
xmlns:map="clr-namespace:iRemote.Location"
Title="Location Finder">
<Frame HasShadow="true" OutlineColor="Color.Black" WidthRequest="700" HeightRequest="300" Padding="3"
BackgroundColor="White">
<mr:StackLayout x:Name="sl_main" Padding="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Orientation="Horizontal" WidthRequest="200">
<StackLayout HorizontalOptions="Start" Orientation="Vertical">
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Label Text="Parcel #" />
<Entry x:Name="txtParcel" WidthRequest="100" />
<Label HorizontalOptions="FillAndExpand" />
<Button x:Name="btnClose" BackgroundColor="#0786a3" BorderRadius="30" TextColor="White"
Text="Close" HorizontalOptions="End" />
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Label Text="Meter #" />
<Entry x:Name="txtMeter" WidthRequest="100" />
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<SearchBar x:Name="search" Placeholder="Search" />
</StackLayout>
<StackLayout Padding="2" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<StackLayout HorizontalOptions="FillAndExpand">
<mr:Image x:Name="img_map" Source="down" HeightRequest="19" WidthRequest="32" />
</StackLayout>
</StackLayout>
</StackLayout>
<StackLayout x:Name="sl_map" Padding="2" HorizontalOptions="FillAndExpand" HeightRequest="5"
VerticalOptions="FillAndExpand" IsVisible="true" WidthRequest="300">
<map:ExtendedMap
BackgroundColor="Blue"
x:Name="MP"
IsShowingUser="true"
MapType="Street" />
</StackLayout>
</mr:StackLayout>
</Frame>
</ContentPage>
Code-Behind:
if (panelShowing)
{
var rect = new Rectangle(this.Width - sl_map.Width, sl_map.Y, sl_map.Width, sl_map.Height);
sl_map.LayoutTo(rect, 250, Easing.CubicIn);
}
else
{
var rect = new Rectangle(this.Width + sl_map.Width - 40, sl_map.Y, sl_map.Width, sl_map.Height);
sl_map.LayoutTo(rect, 200, Easing.CubicOut);
}
However, sl_map simply just shows outside the frame. I want it to not be visible as it crosses the border of the frame. I hope that's clear enough. Again, sorry if I'm not using the correct terminology. I'm a WinForms guy.