We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to retrieve .Text value from Entry control on PopupView.ContentTemplate DataTemplate

Thread ID:

Created:

Updated:

Platform:

Replies:

143669 Mar 31,2019 07:16 AM UTC May 22,2019 02:52 PM UTC Xamarin.Forms 4
loading
Tags: SfPopup
Mitch Harhay
Asked On March 31, 2019 07:16 AM UTC

I have a SfPopup that appears with a Label and Entry controls.  On the Accept command, how do I obtain the value that was entered on the Entry control?

<sfPopup:SfPopupLayout x:Name="popupLayout">
        <sfPopup:SfPopupLayout.PopupView>
            <sfPopup:PopupView AppearanceMode="TwoButton" AcceptButtonText="Save" DeclineButtonText="Cancel">
            <sfPopup:PopupView.ContentTemplate>
                <DataTemplate x:Name="dt">
                            <StackLayout>
                    <Label Text="You have not provided your name yet." 
                           HorizontalTextAlignment="Center"/>
                    <Entry MaxLength="25" Placeholder="Name" x:Name="UserName"/>                            
                </StackLayout>
               </DataTemplate>
            </sfPopup:PopupView.ContentTemplate>
        </sfPopup:PopupView>
            </sfPopup:SfPopupLayout.PopupView>   
    <sfPopup:SfPopupLayout.Content>
         ...
             </sfPopup:SfPopupLayout.Content>
 </sfPopup:SfPopupLayout>

I have implemented the AcceptButtonCustomCommand but I'm unable to determine how to find the Entry control to process the text value that was entered.

popupLayout.PopupView.AcceptCommand = new AcceptButtonCustomCommand(popupLayout);

Thank you.

Subburaj Pandian Veluchamy [Syncfusion]
Replied On April 1, 2019 12:59 PM UTC

Hi Mitch, 
  
Thank you for contacting Syncfusion support. 
  
Based on the provided information, your requirement to access the text from the Entry through the SfPopupLayout.PopupView.AcceptCommand can be achieved. We are working on it to provide solution for the same. We will update you further details in two business days (April 3, 2019). We appreciate your patience until then. 
 
Regards,
Subburaj Pandian V 
 


Subburaj Pandian Veluchamy [Syncfusion]
Replied On April 2, 2019 12:33 PM UTC

Hi Mitch, 
  
Thank you for your patience. 
  
Your requirement to access the Entry text which is loaded inside the PopupView ContentTemplate through the PopupLayout AcceptCommand can be achieved by binding its Text. Refer the below code snippet for the same, 
  
  
<ContentPage.Content> 
    <sfPopup:SfPopupLayout x:Name="popupLayout"> 
        <sfPopup:SfPopupLayout.PopupView> 
            <sfPopup:PopupView AppearanceMode="TwoButton" 
                               AcceptButtonText="Save" 
                               DeclineButtonText="Cancel"> 
                <sfPopup:PopupView.ContentTemplate> 
                    <DataTemplate> 
                        <StackLayout x:Name="mainStack"> 
                            <Label Text="You have not provided your name yet." 
                                   HorizontalTextAlignment="Center"/> 
                            <Entry x:Name="entry" 
                                   Placeholder="Enter name" 
                                   Text="{Binding EntryString,Source={x:Reference viewModel}}"/> 
                        </StackLayout> 
                    </DataTemplate> 
                </sfPopup:PopupView.ContentTemplate> 
            </sfPopup:PopupView> 
        </sfPopup:SfPopupLayout.PopupView> 
        <sfPopup:SfPopupLayout.Content> 
            <StackLayout> 
                <Button Clicked="Button_Clicked" Text="Open"/> 
            </StackLayout> 
        </sfPopup:SfPopupLayout.Content> 
    </sfPopup:SfPopupLayout> 
</ContentPage.Content> 
  
  
 
 
        popupLayout.PopupView.AcceptCommand = new AcceptButtonCustomCommand(); 
…  
 
public class AcceptButtonCustomCommand : ICommand 
{ 
    private Entry entry; 
  
    public event EventHandler CanExecuteChanged; 
  
    public bool CanExecute(object parameter) 
    { 
        return true; 
    } 
  
    public void Execute(object parameter) 
    { 
        var stack = (parameter asSfPopupLayout).PopupView.ContentTemplate.CreateContent(); 
        entry = (stack as StackLayout).FindByName<Entry>("entry"); 
        var text = entry.Text; 
    } 
 
  
  
We have prepared a sample based on your requirement, 
 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Subburaj Pandian V 


Jassim Rahma
Replied On May 22, 2019 12:35 AM UTC

Hi,

I have a ContentPage which I am opening SfPopup from it..

    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:SyncfusionBorder="clr-namespace:Syncfusion.XForms.Border;assembly=Syncfusion.Core.XForms"
    xmlns:SyncfusionPopup="clr-namespace:Syncfusion.XForms.PopupLayout;assembly=Syncfusion.SfPopupLayout.XForms"
    xmlns:SyncfusionImageEditor="clr-namespace:Syncfusion.SfImageEditor.XForms;assembly=Syncfusion.SfImageEditor.XForms"
    x:Class="MyApp.MyProfile">
   
       
           
               
                   
                       
                           
                       
                   
               
           
       
   
   
       
           
           
       

       
           
               
                   
               
           
       

       
           
               
                   
                       
                       
                       
                       
                   
                   
                       
                       
                   
                   
                       
                   
                   
                       
                   
               
           
       
   



and this is my AcceptButtonCustomCommand:

public class AcceptButtonCustomCommand : ICommand
{
    private SfImageEditor imageEditor;
    private Image image;
    public event EventHandler CanExecuteChanged;

    public bool CanExecute(object parameter)
    {
        return true;
    }

    public void Execute(object parameter)
    {
        var stack = (parameter as SfPopupLayout).PopupView.ContentTemplate.CreateContent();
        imageEditor = (stack as StackLayout).FindByName("ImageEditorMyPhoto");
        var source = imageEditor.Source;

        ContentPage parentPage = ((parameter as SfPopupLayout).Parent as ContentPage);
        image = parentPage.FindByName("ImageMyProfileMyPhoto");

        image.Source = source;
    }
}


I want to know how can I show the edited image from my Popup's ImageEditor into my ContentPage's Image?


Because when I try the  above code I get:

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object. occurred


On this line:

imageEditor = (stack as StackLayout).FindByName("ImageEditorMyPhoto");
var source = imageEditor.Source;




Thanks,



Pradeep Kumar Balakrishnan [Syncfusion]
Replied On May 22, 2019 02:52 PM UTC

Hi Jassim, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your query “How to load the edited image in SfimageEditor to image control in the content pageand run-time changes are not reflected, since we are creating a new instance of the template and not accessing the existing instances. However your requirement can be achieved by using ImageEditor ImageSaving or ImageSaved event. Please refer the following UG link to get the changed image location or stream from ImageEditor. 
 
 
Please refer the following KB link to load to the modified image. 
 
 
Regards, 
Pradeep Kumar B 
 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;