I just wanted to ask if there is any way to justify text in a Label. I am using Xamarin Forms Xaml.
Thanks.
UPDATE:
As for now, it is not possible to justify text. Most of the answers were about centering the text, but it is not what I asked. One way could be to use Renderer as by Timothy.
Though you can't stretch label's text to a full width using Xamarin.Forms features, it's easily achieved with a platform renderer.
Most Xamarin platforms have the text justification feature available in corresponding native elements, and it's just a matter of setting a single attribute of a native element. I suppose the reason for not adding this feature to standard Xamarin.Forms label is lagging of platforms in that capability, e.g. Android had Android.Text.JustificationMode.InterWord flag added only in version 8.1
Below you can see Android renderer implementation:
using Android.Content;
using Saplin.CPDT.UICore.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Saplin.CPDT.UICore.Controls.ExtendedLabel), typeof(Saplin.CPDT.Droid.ExtnededLabelRenderer))]
namespace Saplin.CPDT.Droid
{
public class ExtnededLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
public ExtnededLabelRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var el = (Element as ExtendedLabel);
if (el != null && el.JustifyText)
{
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
Control.JustificationMode = Android.Text.JustificationMode.InterWord;
}
}
}
}
}
Your create renderer class in native project
You add assembly: ExportRenderer attribute
You set TextView's JustificationMode
In my example I used ExtenedLabel subclass of Xamarin.Forms.Label with extra property JustifyText to let setting the justification of the text. That's how the subclassed control can be declared:
using System;
using Xamarin.Forms;
namespace Saplin.CPDT.UICore.Controls
{
public class ExtendedLabel : Label
{
public static readonly BindableProperty JustifyTextProperty =
BindableProperty.Create(
propertyName: nameof(JustifyText),
returnType: typeof(Boolean),
declaringType: typeof(ExtendedLabel),
defaultValue: false,
defaultBindingMode: BindingMode.OneWay
);
public bool JustifyText
{
get { return (Boolean)GetValue(JustifyTextProperty); }
set { SetValue(JustifyTextProperty, value); }
}
}
}
Examples of platform renderers for WPF and macOS.
The current way to do this is by using HorizontalTextAlignment and the values for the TextAlignment enumeration are:
Center = Center-aligned text
Start = Left-aligned
End = Right-aligned
Center a label and its text example:
<Label x:Name="Description" HorizontalTextAlignment="Center"
VerticalOptions="Center" HorizontalOptions="Center" />
In xaml you can use html to justify your text.
<Label LineBreakMode="WordWrap" TextType="Html" TextColor="Black">
<Label.Text><p style="text-align:justify;">
Your text here
<p></Label.Text>
Use the XAlign property
Label lbl = new Label();
lbl.Text = "I'm a Label!";
lbl.XAlign = TextAligntment.Start; // Start, Center, End are valid
As it can't be done directly within a label, a workaround is to use the new FlexLayout from Xamarin.Forms 3. The idea is to split the text at space character and insert corresponding label in the FlexLayout with JustifyContent set to SpaceBetween.
Example :
XAML
<Frame
HorizontalOptions="Center"
Margin="20,50,20,0"
Padding="10"
WidthRequest="300"
HasShadow="true">
<FlexLayout
x:Name="TextContainer"
Direction="Row"
AlignItems="End"
JustifyContent="SpaceBetween"
Wrap="Wrap"/>
</Frame>
Code behind
var textparts = "This is a long text to be justified"
.Split(' ', StringSplitOptions.RemoveEmptyEntries)
.Select(x => new Label
{
Text = x,
FontSize = 12,
TextColor = Color.FromHex("#555555"),
Margin = new Thickness(1, 0)
});
foreach (var textpart in textparts)
TextContainer.Children.Add(textpart);
What sort of container are you using to hold the text? Having a StackLayout with HorizontalOptions of FillAndExpand, along with the XAlign, might do it, but only if your text is only one line long per control.
Try this:
<StackLayout HorizontalOptions="FillAndExpand" Padding="0, 10, 0, 10" Spacing="0">
<Label Text="Test message" XAlign="Center"/>
<Label FontSize="Small" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." LineBreakMode="WordWrap"
XAlign="Center" />
</StackLayout>
If you use the Label under relativeLayout you can justify the label..
The trick is you must fill the width & height as per parent..
So I use HeightConstraint,WidthConstraint with factor=1.. so it take full width & height of the parent..
<RelativeLayout >
<Label Text="My text"
FontSize="20"
HorizontalOptions="Center"
VerticalOptions="Center"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=1,Constant=0}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=1,Constant=0}" />
</RelativeLayout>
I've been able to successfully achieve this by using nested grids. Hope this helps someone!
<Grid HorizontalOptions="Fill" Padding="5,2">
<Grid Margin="8, 85,8,0" VerticalOptions="Center" RowSpacing="0" >
<Label Grid.Row="0" x:Name="PostTitle" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"
Text="Display Text" Padding="10,10" LineHeight="20" BackgroundColor="Black" TextColor="WhiteSmoke" />
<Label Grid.Row="1" x:Name="PostDate" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"
Text="Your Text Here" FontSize="Micro" Padding="10,10" LineHeight="10"
BackgroundColor="Black" TextColor="WhiteSmoke" />
</Grid>
</Grid>
To Justify Text in UITableViewCell TextLabel - Xamarin IOS
UIStringAttributes stringAttributes = new UIStringAttributes
{
ParagraphStyle = new NSMutableParagraphStyle() { Alignment = UITextAlignment.Justified }
};
var attributedText = new NSMutableAttributedString(cell.TextLabel.Text);
attributedText.AddAttributes(stringAttributes, new NSRange(0, cell.TextLabel.Text.Length));
cell.TextLabel.AttributedText = attributedText;
Custom Label
using System;
using Xamarin.Forms;
namespace YourNameSpace.Controls
{
public class CustomLabel : Label
{
public static readonly BindableProperty JustifyTextProperty =
BindableProperty.Create(nameof(JustifyText), typeof(bool), typeof(CustomLabel), false, BindingMode.TwoWay);
public bool JustifyText
{
get { return (bool)GetValue(JustifyTextProperty); }
set
{
SetValue(JustifyTextProperty, value);
}
}
public CustomLabel()
{
}
}
}
iOS Custom Label Renderers
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using YourNameSpace.Controls;
using YourNameSpace.iOS.Renderers;
[assembly: ExportRenderer(typeof(CustomLabel), typeof(CustomLabelRenderer))]
namespace YourNameSpace.iOS.Renderers
{
public class CustomLabelRenderer : Xamarin.Forms.Platform.iOS.LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control == null || this.Element == null) return;
Control.TextAlignment = UITextAlignment.Justified;
}
}
}
Android Custom Label Renderers
using Android.Content;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using YourNameSpace.Controls;
using YourNameSpace.Droid.Renderers;
[assembly: ExportRenderer(typeof(CustomLabel), typeof(CustomLabelRenderer))]
namespace YourNameSpace.Droid.Renderers
{
public class CustomLabelRenderer : Xamarin.Forms.Platform.Android.LabelRenderer
{
public CustomLabelRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var element = (Element as CustomLabel);
if (element != null && element.JustifyText)
{
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
Control.JustificationMode = Android.Text.JustificationMode.InterWord;
}
}
}
}
}
Related
I have a SearchResult class that binds to a ListView. What I want to do specifically is highlight the snippet inside the search result text that matches the query the user entered.
The relevant XAML looks something like this (omitting the fluff):
<DataTemplate>
<StackPanel>
<!-- Search result -->
<RichTextBlock>
<!-- Would this idea work? -->
<RichTextBlock.TextHighlighters>
<TextHighlighter>
<TextHighlighter.Ranges>
<!-- Add the bound range here-->
<!-- {Binding Range} or text highlighter or something -->
</TextHighlighter.Ranges>
</TextHighlighter>
</RichTextBlock.TextHighlighters>
<Paragraph>
<Run Text="{Binding Text}"></Run>
</Paragraph>
</RichTextBlock>
</StackPanel>
</DataTemplate>
I can add whatever property from the SearchResult class, be it a TextHighlighter or a TextRange. I just don't know whether the XAML syntax allows plugging in that value.
I've also thought of doing this in code, but I do want to keep the search item template inside the XAML, and not put it in C#. However, it would be possible to do something like lvSearchResults.Items[i]... or whatever it takes to put in the highlighter or range. I just can't figure out the correct method at the moment.
If you are planning to create a locally highlighted search result list, you can try this way:
Create a search result class
public class SearchResult
{
public string DisplayText { get; set; }
public string HighlightText { get; set; }
}
Create a UserControl to show the result
SearchResultBlock.xaml
<Grid>
<TextBlock x:Name="ResultBlock" TextWrapping="Wrap" MaxLines="2"
TextTrimming="CharacterEllipsis"/>
</Grid>
SearchResultBlock.xaml.cs
public sealed partial class SearchResultBlock : UserControl
{
public SearchResultBlock()
{
this.InitializeComponent();
}
public SearchResult Result
{
get { return (SearchResult)GetValue(ResultProperty); }
set { SetValue(ResultProperty, value); }
}
public static readonly DependencyProperty ResultProperty =
DependencyProperty.Register("Result", typeof(SearchResult), typeof(SearchResultBlock), new PropertyMetadata(null,new PropertyChangedCallback(Result_Changed
private static void Result_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if(e.NewValue!=null && e.NewValue is SearchResult data)
{
var instance = d as SearchResultBlock;
instance.ResultBlock.Inlines.Clear();
var sp = data.DisplayText.Split(data.HighlightText);
instance.ResultBlock.Inlines.Add(new Run { Text = sp.First() });
instance.ResultBlock.Inlines.Add(new Run { Text = data.HighlightText, Foreground = new SolidColorBrush(Colors.Red) });
if (sp.Length > 1)
instance.ResultBlock.Inlines.Add(new Run { Text = sp.Last() });
}
}
}
Use it in DataTemplate
<DataTemplate x:DataType="SearchResult" x:Key="ResultItemTemplate">
<SearchResultBlock Result="{Binding}"/>
</DataTemplate>
By string splitting, create different types of Runs and merge them in the TextBlock. This can also achieve the highlighting effect.
Best regards.
I want to show a label when i click on my item in my listview.
The real problem i don't know how to link between my viewmodel and my views
I want modify my label in viewmodel but I don't know if its possible currently.
My xaml :
<StackLayout>
<Label x:Name="labelperso"
Text="{Binding newProduct}"
IsVisible="{Binding Addproduct}"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
BackgroundColor="#000000"
FontSize="20"
Opacity="0"/>
<ListView ItemsSource="{Binding Products}" CachingStrategy="RecycleElement" RowHeight="50" >
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding CodeReferenceLibelle}" TextColor="Black"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Behaviors>
<b:EventToCommandBehavior EventName="ItemSelected" Command="{Binding
SelectCommand}" Converter="{StaticResource SelectedItemConverter}"/>
</ListView.Behaviors>
my viewmodel :
#region labelperso property
private string _newProduct;
public string newProduct
{
get { return _newProduct; }
set { SetProperty(ref _newProduct, value); }
}
#endregion
#region Addproduct property
private bool _Addproduct;
public bool Addproduct
{
get { return _Addproduct; }
set { SetProperty(ref _Addproduct, value); }
}
#endregion
when I click on my item :
async Task Select()
{
newProduct = "Produit ajouté !";
basketManager.AddProductSkuAsync(sku);
newProduct = "";
await Task.Run(() => ShowText());
}
//I have tried this but I can't use my label in my view
async Task ShowText()
{
await labelperso.FadeTo(1);
await Task.Delay(1000);
await labelperso.FadeTo(0);
}
Why are you want to take the label "labelperso" in VM ? you can use it in xaml.cs instead.
You just need to add the event ItemSelected like this:
<ListView ItemsSource="{Binding Products}" ItemSelected="OnSelection">
In xaml.cs
void OnSelection(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null)
{
return;
}
//suppose the binding Object is Product
Product product = (Product)e.SelectedItem;
//labelperso.Text = "name = " + product.Name;
labelperso.FadeTo(1);
Task.Delay(1000);
labelperso.FadeTo(0);
}
Normally, VM are unrelated to Xaml, and we should not get labels from VM.
And we don't recommend it.But if you must, you can pass the Label in from the xaml.cs file like this:
You can define a variable in yourpage.xaml.cs:
public Label pageLabel;
and initial like this:
pageLabel = labelperso;
BindingContext = new YourViewmodel(this);
And in YourViewmodel.cs:
public Label ss;
public YourViewmodel(ContentPage parentPage)
{// here HomePage is your contentPage name of the page`
ss = ((HomePage)parentPage).pageLabel;//after this you can use it
}
You need to add a SelectedProduct property to your VM.
private string _SelectedProduct;
public string SelectedProduct
{
get { return _SelectedProduct; }
set { SetProperty(ref _SelectedProduct, value); }
}
You can then bind your ListView's SelectedItem to it
<ListView ItemsSource="{Binding Products}"
SelectedItem="{Binding SelectedProduct}"
CachingStrategy="RecycleElement"
RowHeight="50" >
You can then control the visibility of your label by binding to SelectedProduct via a "nullToVisibility" converter, or by using triggers etc.
You should try to use MVVM pattern rather than hacking with code behind.
Using MVVM you can add a Visible property to your viewmodel and bind the IsVisible property of the label to it.
Code will be much easy to read and maintain.
I am working on Xamarin.Forms. I have login page for that I am using StackLayout with ScrollView.
Code following
<?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="simpleListView.Pages.LoginPage">
<ContentPage.Content>
<ScrollView Orientation="Vertical" x:Name="scroll">
<StackLayout Padding="20">
<Label Margin="20" HorizontalOptions="Center" Text="Login below" ></Label>
<BoxView HeightRequest="150" Color="Accent"></BoxView>
<Entry Text="{Binding Email}" x:Name="txtEmail" Placeholder="Email"></Entry>
<Entry Text="{Binding Password}" x:Name="txtPass" Placeholder="Paasword"></Entry>
<Button x:Name="btnLogin" BackgroundColor="Blue" Text="Login" Command="{Binding SubmitCommand}"></Button>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
But the code above not scrolling layout towards top when keypad open & hiding almost half of Login button. How can I implement scrolling when keypad open? I am not much interested in using custom renderers.
See login page screeshot
Since there is (as far as I am informed) no good way to get the actual keyboard height for android via a DependencyService, using that scrollview is the right approach to begin with, however what you want to do is UI customizing which leads to custom renderers. Saying "i want a cool custom UI but I am not interested in custom renderers" is like "I want to drive, but I am not interested in wheels".
However, to make it a bit easier for you, I happen to have code for a custom renderer, which gives the desired result:
Android
[assembly: ExportRenderer(typeof(ModernLogin), typeof(ModernLoginPageRenderer))]
namespace MyApp.Droid.Renderer
{
public class ModernLoginPageRenderer : PageRenderer
{
public ModernLoginPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
// Set SoftInput.AdjustResize for this window
if (e.NewElement != null)
{
(this.Context as FormsApplicationActivity).Window.SetSoftInputMode(SoftInput.AdjustResize);
}
}
protected override void OnWindowVisibilityChanged([GeneratedEnum] ViewStates visibility)
{
// Revert to default SoftInputMode after moving away from this window
if (visibility == ViewStates.Gone)
{
(this.Context as FormsApplicationActivity).Window.SetSoftInputMode(SoftInput.AdjustPan);
}
base.OnWindowVisibilityChanged(visibility);
}
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
base.OnLayout(changed, left, top, right, bottom);
}
}
}
iOS
[assembly: ExportRenderer(typeof(ModernLogin), typeof(ModernLoginPageRenderer))]
namespace MyApp.iOS.Renderer
{
public class ModernLoginPageRenderer : PageRenderer
{
NSObject observerHideKeyboard;
NSObject observerShowKeyboard;
public override void ViewDidLoad()
{
base.ViewDidLoad();
var cp = Element as ModernLogin;
if (cp != null)
{
foreach (var g in View.GestureRecognizers)
{
g.CancelsTouchesInView = true;
}
}
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
observerHideKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification);
observerShowKeyboard = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification);
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
NSNotificationCenter.DefaultCenter.RemoveObserver(observerHideKeyboard);
NSNotificationCenter.DefaultCenter.RemoveObserver(observerShowKeyboard);
}
void OnKeyboardNotification(NSNotification notification)
{
if (!IsViewLoaded) return;
var frameBegin = UIKeyboard.FrameBeginFromNotification(notification);
var frameEnd = UIKeyboard.FrameEndFromNotification(notification);
var page = Element as ModernLogin;
if (page != null)
{
var padding = page.Padding;
page.Padding = new Thickness(padding.Left, padding.Top, padding.Right, padding.Bottom + frameBegin.Top - frameEnd.Top);
}
}
}
}
Make sure you replace the name of "ModernLogin" with the name of your login page class. If your LoginPage is a regular ContentPage, I would recommend creating a new class inheriting from ContentPage.
I have made an application in Xamarin From. Design the UI in xaml. My issue is when i define the Keyboard telephone in entry field it allow to input negative value in android app but in IOS it not allowed.
<StackLayout Spacing="20" Padding="0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Entry Text="{Binding Item.TextProvider2017}" HorizontalTextAlignment="End" FontSize="Small" WidthRequest="140" MinimumWidthRequest="60" Placeholder="For 2017" Keyboard="Telephone" Completed="NoOfProvider_Completed" Unfocused="NoOfProvider_Unfocused"/>
<Entry Text="{Binding Item.TextProvider2018}" HorizontalTextAlignment="End" FontSize="Small" WidthRequest="140" MinimumWidthRequest="60" Placeholder="For 2018" Keyboard="Telephone"/>
<Entry Text="{Binding Item.TextProvider2019}" HorizontalTextAlignment="End" FontSize="Small" WidthRequest="140" MinimumWidthRequest="60" Placeholder="For 2019" Keyboard="Telephone"/>
<Entry Text="{Binding Item.TextProvider2020}" HorizontalTextAlignment="End" FontSize="Small" WidthRequest="140" MinimumWidthRequest="60" Placeholder="For 2020" Keyboard="Telephone"/>
</StackLayout>
Keypad in Android:
Keypad in IOS:
In Android keypad have negative sign but IOS don't have. IS there any way to make both same.
This is the old answer, see below for an updated version
You're going to want to create a custom renderer for the Entry control which has the default behavior for UWP and Android, while adding a custom InputAccessoryView to your iOS UITextField.
Here's what your custom renderer for iOS might look like:
class MinusButtonEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null) return;
UIBarButtonItem button = new UIBarButtonItem("-", UIBarButtonItemStyle.Plain, (sender, args) =>
{
var position = Control.SelectedTextRange.Start;
var idx = (int) Control.GetOffsetFromPosition(Control.BeginningOfDocument, position);
Element.Text.Insert(idx, "-");
});
UIToolbar toolbar = new UIToolbar()
{
Items = new [] { button }
};
Control.InputAccessoryView = toolbar;
}
}
This code basically creates a button, adds that to a toolbar, and then assigns that toolbar to the underlying UITextField. You will of course want to customize the toolbar and toolbar button to suit your needs.
EDIT:
There's a better way to do this using Effects in Xamarin Forms.
This class goes in the iOS project and is the main effect:
using MyApp;
using UIKit;
using Xamarin.Forms;
[assembly:ResolutionGroupName("Xamarin")]
[assembly:ExportEffect(typeof(MinusButtonEntryEffect), "MinusButtonEntryEffect")]
namespace MyApp
{
public class MinusButtonEntryEffect : PlatformEffect<UIView, UITextField>
{
protected override void OnAttached()
{
if (Control == null) return;
var element = Element as Entry;
if (element == null) return;
UIBarButtonItem button = new UIBarButtonItem("-", UIBarButtonItemStyle.Plain, (sender, args) =>
{
var position = Control.SelectedTextRange.Start;
var idx = (int)Control.GetOffsetFromPosition(Control.BeginningOfDocument, position);
element.Text = element.Text.Insert(idx, "-");
});
UIToolbar toolbar = new UIToolbar()
{
Items = new[] { button }
};
Control.InputAccessoryView = toolbar;
}
protected override void OnDetached()
{
Control.InputAccessoryView = null;
}
}
}
This code goes in the PCL and allows us to access the effect from XAML:
public class MinusButtonEntryEffect : RoutingEffect
{
public MinusButtonEntryEffect () : base ("Xamarin.MinusButtonEntryEffect") { }
}
So your XAML would look something like this:
<Entry Text="{Binding Item.TextProvider2017}" HorizontalTextAlignment="End" FontSize="Small" WidthRequest="140" MinimumWidthRequest="60" Placeholder="For 2017" Keyboard="Telephone">
<Entry.Effects>
<local:MinusButtonEntryEffect />
</Entry.Effects>
</Entry>
Make sure that local is whatever namespace your effect is in, for example:
xmlns:local="clr-namespace:MyApp"
I got a bit stuck on a problem and I was wondered if it's possible you can make a video on my problem it seems may others may have the same problem but, I been looking online but no real straight forward solution to the issue. The problem is, for instance, I have a stack layout in a content page page1.xaml and I added labels to that page 4 of them and I set properties for those labels setters and getters. however, if I make page2.xaml how would I be able to move the labels along with the data to page2.xaml basically reuse the data/labels declared from page1.xaml to page2.xaml throughout the app? here is what I have so far.
<StackLayout>
<StackLayout x:Name = "CustomerOrderStackLayout" Orientation = "Horizontal" HorizontalOptions = "Center" Padding = "20" >
<Label x:Name ="CustomerOrderNumberLabel" HorizontalOptions = "Center" />
</StackLayout>
<StackLayout Orientation = "Vertical" Padding = "20" >
<Label x:Name ="CustomerFirstNameLabel"
VerticalOptions = "Start" />
<Label x:Name ="CustomerLastNameLabel"
VerticalOptions = "Start" />
<Label x:Name ="CustomerAddressLabel"
VerticalOptions = "Start" />
<Label x:Name ="CustomerZipCodeLabel"
VerticalOptions = "Start"/>
<Label x:Name ="CustomerPhoneNumberLabel"
VerticalOptions = "Start"/>
</StackLayout>
</StackLayout>
</ContentPage>
public partial class CustomerInfoContentV : ContentPage
{
public CustomerInfoContentV()
{
InitializeComponent();
orderNum = "N";
FirstName = "Nl";
LastName = "Jk";
Address = "203030 drive";
ZipCode = "77088";
PhoneNumber = "833-223-2222";
}
public string orderNum
{
get
{
return CustomerOrderNumberLabel.Text;
}
set
{
CustomerOrderNumberLabel.Text = value;
}
}
public string FirstName
{
get
{
return CustomerFirstNameLabel.Text;
}
set
{
CustomerFirstNameLabel.Text = value;
}
}
public string LastName
{
get
{
return CustomerLastNameLabel.Text;
}
set
{
CustomerLastNameLabel.Text = value;
}
}
public string Address
{
get
{
return CustomerAddressLabel.Text;
}
set
{
CustomerAddressLabel.Text = value;
}
}
public string ZipCode
{
get
{
return CustomerZipCodeLabel.Text;
}
set
{
CustomerZipCodeLabel.Text = value;
}
}
public string PhoneNumber
{
get
{
return CustomerPhoneNumberLabel.Text;
}
set
{
CustomerPhoneNumberLabel.Text = value;
}
}
}
I want to know is there a way to take this what i have and reuse it on a whole different contentpage thats my issue i want to take this what i created and reuse it through out the app is this possible? can anyone lead me in the right direction! please thanks :)
If I am understanding you correct. You can use templates. https://developer.xamarin.com/guides/xamarin-forms/templates/control-templates/creating/ . For my projects I just create a code based template and render it whenever I want it and wherever I want them.