I want to concatenate the FirstName and LastName. So I have implemented the FullName method that should return concatenated the FirstName and LastName but it does not happen. How to fix it ?
This is ContentView. Please, take a look to the line with "Label Text="{Binding FullName}"".
<ContentView.Content> <StackLayout> <Grid> <BoxView Grid.RowSpan="3" BackgroundColor="LightGreen"/> <Label Text="{Binding FullName}" Grid.Row="0" FontSize="20" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand"/> <Label Grid.Row="1" Text="{Binding PhoneNumber}" FontSize="20" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand"/> <StackLayout Grid.Row="2" Orientation="Horizontal"> <Label Text="Select: " FontSize="20" VerticalOptions="Start" HorizontalOptions="Start"/> <CheckBox VerticalOptions="Start" HorizontalOptions="Start"/> </StackLayout> </Grid> </StackLayout> </ContentView.Content>
This is the code for the ContentView above
[XamlCompilation(XamlCompilationOptions.Compile)] public partial class Participant : ContentView { public static readonly BindableProperty FirstNameBindableProperty = BindableProperty.Create( "FirstName", typeof(string), typeof(string), string.Empty); public static readonly BindableProperty LastNameBindableProperty = BindableProperty.Create( "LastName", typeof(string), typeof(string), string.Empty); public static readonly BindableProperty PhoneNumberBindableProperty = BindableProperty.Create( "PhoneNumber", typeof(string), typeof(string), string.Empty); public string FirstName { get { return (string)GetValue(FirstNameBindableProperty); } set { SetValue(FirstNameBindableProperty, value); } } public string LastName { get { return (string)GetValue(LastNameBindableProperty); } set { SetValue(LastNameBindableProperty, value); } } public string PhoneNumber { get { return (string)GetValue(PhoneNumberBindableProperty); } set { SetValue(PhoneNumberBindableProperty, value); } } public string FullName => $"{FirstName} {LastName}"; public Participant() { InitializeComponent(); this.BindingContext = this; } }
How to concatenate the FirstName and LastName ?