Asked by:
Passing Value from XAML to ViewModel

Question
-
Hi,
I am using Syncfusion in my project and I am showing this ListView:
<SyncfusionListView:SfListView x:Name="ListViewNewItemLocations" SelectionBackgroundColor="Transparent" IsVisible="False" IsScrollBarVisible="false" AutoFitMode="Height" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" ItemAppearing="ListViewNewItemLocations_ItemAppearing" ItemTapped="ListViewNewItemLocations_ItemTapped"> <SyncfusionListView:SfListView.ItemTemplate> <DataTemplate> <Frame BorderColor="Black" CornerRadius="25" HasShadow="False"> <StackLayout> <Label Margin="0,0,0,0" Text="{Binding country_name}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" /> <Label Margin="0,0,0,0" Text="{Binding location_address}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" /> <Label Margin="0,0,0,0" Text="{Binding telephone}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" TextColor="Black" HorizontalTextAlignment="Start" FontSize="15" LineBreakMode="WordWrap" /> <Grid HorizontalOptions="FillAndExpand"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Syncfusionbuttons:SfButton x:Name="ButtonNewItemLocationEdit" Clicked="ButtonNewItemLocationEdit_Clicked_1" ClassId="abcd" BackgroundColor="Brown" Text="Edit" Grid.Column="0" CornerRadius="25" /> <Syncfusionbuttons:SfButton x:Name="ButtonNewItemLocationDelete" IsVisible="{Binding IsDeleteVisible}" BackgroundColor="Red" Text="Delete" Grid.Column="1" CornerRadius="25" /> </Grid> </StackLayout> </Frame> </DataTemplate> </SyncfusionListView:SfListView.ItemTemplate> </SyncfusionListView:SfListView>
and I have I have a ViewModel like this:
using System; using System.Collections.Generic; using System.Text; using Syncfusion.ListView.XForms; using Syncfusion.XForms.PopupLayout; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Xamarin.Forms; namespace Zeera { public class ViewModelItemLocation : INotifyPropertyChanged { public Command<object> TapCommand { get; set; } SfPopupLayout popupLayout; public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string name) { if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(name)); } public ViewModelItemLocation() { TapCommand = new Command<object>(EditButtonTapped); } private void EditButtonTapped(object obj) { popupLayout = new SfPopupLayout(); popupLayout.PopupView.HeightRequest = 500; popupLayout.PopupView.WidthRequest = 300; // popupLayout.BindingContext = ModelBinding; popupLayout.PopupView.ContentTemplate = new DataTemplate(() => { var mainStack = new StackLayout(); mainStack.BackgroundColor = Color.AliceBlue; var image = new Image(); image.SetBinding(Image.SourceProperty, new Binding("ContactImage")); var grid = new Grid(); var NameLabel = new Label() { Text = "Customer Name " }; NameLabel.HorizontalOptions = LayoutOptions.Start; var label1 = new Entry() { }; label1.SetBinding(Entry.TextProperty, new Binding("ContactName")); label1.HorizontalOptions = LayoutOptions.Start; var NumberLabel = new Label() { Text = "HERE LOCATIO ID" }; NumberLabel.HorizontalOptions = LayoutOptions.Start; var label2 = new Entry() { }; label2.SetBinding(Entry.TextProperty, new Binding("ContactNumber")); label2.HorizontalOptions = LayoutOptions.Start; grid.Children.Add(NameLabel, 0, 0); grid.Children.Add(label1, 1, 0); grid.Children.Add(NumberLabel, 0, 1); grid.Children.Add(label2, 1, 1); mainStack.Children.Add(image); mainStack.Children.Add(grid); return mainStack; }); popupLayout.PopupView.ShowHeader = false; popupLayout.PopupView.ShowFooter = false; popupLayout.HeightRequest = 500; popupLayout.WidthRequest = 500; popupLayout.Show(); } } }
I have a questions here: How can I pass item_location_id (binded to the SfListView) to the ViewModelItemLocation and then show it in the NumberLabel (created in the ViewModelItemLocation code behind)
Thanks,
- Moved by Wendy ZangMicrosoft contingent staff Tuesday, April 23, 2019 7:40 AM
Saturday, April 20, 2019 11:41 PM
All replies
-
Hi Jassim Rahma,
Thank you for posting here.
Since your question is more related to Xamarin forum, I will move it to Xamarin forum for suitable support.
The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.
Best Regards,
Wendy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Monday, April 22, 2019 8:01 AM