i am new to Xamarin. in the app that a developing, the main-page contains three buttons that navigate to three popup pages. page one and two both contain a picker and the third page a label. i would like to know how can i bind the label in the third page to receive data from both page one and two depending on the page the user selected a value? so if the user navigate to page 1 and selects a value from the picker, the label should only display the value from page 1, same way if the user select a value from page 2 this same label should only display what was selected in page 2. it should always display one data value.
i hope its understandable.
thank you in advance
First page
<StackLayout> <Label Text="Laterality:" TextColor="Black" FontSize="Default" ></Label> <Picker SelectedItem="{Binding PICKER1}" WidthRequest="120" FontSize="10" TextColor="Black" VerticalOptions="Center" BackgroundColor="WhiteSmoke"> <Picker.Items> <x:String>15 cm</x:String> <x:String>30 cm</x:String> <x:String>45 cm</x:String> <x:String>60 cm</x:String> <x:String>75 cm</x:String> <x:String>90 cm</x:String> </Picker.Items> </Picker>
On the second page i have this
<StackLayout BackgroundColor="White"> <Label Text="orientation:" TextColor="Black" FontSize="Default" ></Label> <Picker SelectedItem="{Binding PICKER2}" WidthRequest="120" FontSize="10" VerticalOptions="Center" BackgroundColor="WhiteSmoke"> <Picker.Items> <x:String>Vertical</x:String> <x:String>horizontal</x:String> </Picker.Items> </Picker>
lastly on my last page i have a label which is suppose retrieve the values from the fist and second page depending on which page i did something on. so if the user selects something on page 1, the label should only display what is selected from page 1 and and viceversa.
<Label Text="{Binding DisplayPICKER1}" Margin="5" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand"></Label>
This is the MainViewModel. currently with this MainViewModel i need 2 labels, but i would like to use just one label
string picker1 = string.Empty; public string PICKER1 { get => picker1; set { if (picker1 == value) return; else { picker1 = value; OnPropertyChanged(nameof(PICKER1)); OnPropertyChanged(nameof(DisplayPICKER1)); } } } public string DisplayPICKER1 => $"laterality:{PICKER1}"; string picker2 = string.Empty; public string PICKER2 { get => picker2; set { if (picker2 == value) return; else { picker2 = value; OnPropertyChanged(nameof(PICKER2)); OnPropertyChanged(nameof(DisplayPICKER2)); } } } public string DisplayPICKER2 => $"Orientation:{PICKER2}";
baseview
public class baseview : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }