Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Read Entry Text with Xamarin.Prism

Hi,
I'm trying to create my first Prism App, how can I read the text value of an entry when i click on a button?

<StackLayout>
        <Entry Placeholder="Class" />
        <Button Text="Aggiungi" Command="{Binding AddClassCmd}"/>

        <ListView ItemsSource="{Binding Classes}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Margin="8">
                            <Label Text="{Binding Name}" FontAttributes="Bold" />
                            <Label Text="{Binding Days}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

That's my xaml code, i need to read the text of the entry when i click on the button.

thanks

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    @sneakol90
    You can try the following code:

     <Entry x:Name="name" Placeholder="Class"/>
     <Button x:Name="mybtn" Text="Aggiungi" Clicked="mybtn_Clicked"/>
    

    You can get value from Entry.Text property. For example:

       private void mybtn_Clicked(object sender, EventArgs e)
     {
         var nameValue = name.Text;
       }
    
  • NMackayNMackay GBInsider, University admin
    edited October 2018

    You can pass the value of the entry as a parameter to your command using relative source binding....or just bind the entry to a property in your viewmodel and check the value when command executes

            <Entry x:Name="EntryClassName" Placeholder="Class" />
            <Button Text="Aggiungi" Command="{Binding AddClassCmd}"
                                    CommandParameter="{Binding Source={x:Reference EntryClassName}, Path=Text}"/>
    
  • NMackayNMackay GBInsider, University admin
    edited October 2018

    @sneakol90

    This has nothing to do do with Prism, the binding, navigation etc is Xamarin Forms, Prism wraps these concepts to deliver an easy way to build nice apps.

Sign In or Register to comment.