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. Image for the cookie policy date

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

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.

4 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team 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 
 



SP Subburaj Pandian Veluchamy Syncfusion Team 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 



JR Jassim Rahma 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,




PK Pradeep Kumar Balakrishnan Syncfusion Team 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 
 
 


Loader.
Up arrow icon