Issue
I can't share a binding name here is the code
I can't call the binding name, I just share a string, please could someone help me on how to call the binding name?
<?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:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="XF_ListViewDetails_MVVM.Views.ListDetailPage"
Title="Lanches"
BackgroundColor="Maroon">
<ContentPage.Content>
<ListView ItemsSource="{Binding Lanches}"
HasUnevenRows="True"
SeparatorVisibility="None"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10" RowSpacing="10" ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label x:Name="Nome666"
Grid.Column="1"
Text="{Binding Nome}"
FontSize="Medium"
TextColor="White"
VerticalOptions="End"/>
<Button x:Name="Button666"
Text="Compartilhar Texto"
Clicked="ButtonClicked"
/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
here is the code in cs
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using XF_ListViewDetails_MVVM.ViewModels;
using Xamarin.Essentials;
using System.Threading.Tasks;
namespace XF_ListViewDetails_MVVM.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListDetailPage : ContentPage
{
public ListDetailPage(string Nome, string Ingredientes, string fonte)
{
InitializeComponent();
BindingContext = new ListDetailPageViewModel();
}
async void ButtonClicked(object sender, System.EventArgs args)
{
await CompartilharTexto(Nome666.Text);
}
public async Task CompartilharTexto(string texto)
{
await Share.RequestAsync(new ShareTextRequest
{
Text = texto,
Title = "Compartilhando Texto"
});
}
}}
the code does not share I need to know how to call the binding name on the home page, it does not run in the model only on the home page
Solution
you can get the value of the selected row from the binding context
async void ButtonClicked(object sender, System.EventArgs args)
{
var btn = (Button)sender;
var item = (YourClassNameGoesHere)btn.BindingContext;
await CompartilharTexto(item.Nome);
}
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.