Home > Mobile >  share tex with binding text xamarin forms
share tex with binding text xamarin forms

Time:06-19

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

CodePudding user response:

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);
}

CodePudding user response:

    public class ListDetailPageViewModel

    {
        public ObservableCollection<ListModel> Lanches { get; set; }
        public ListDetailPageViewModel()
        {
            Lanches = new ObservableCollection<ListModel>();

            Lanches.Add(new ListModel
            {
                Nome = "Cheese Burger Completo",
        
            });

            Lanches.Add(new ListModel
            {
                Nome = "Cheese Salada Completo",
            });
            Lanches.Add(new ListModel
            {
                Nome = "Cheese Burger com Ovo ",
                 });
        
        
        
        
        
        }
    }
}

CodePudding user response:

namespace XF_ListViewDetails_MVVM.Models
{
    public class ListModel
    {
        public string Nome { get; set; }

        
        public string Detalhe { get; set; }
        public string Imagem { get; set; }
        public string Ingredientes { get; set; }
    }
}
  • Related