XF ControlTemplate and dynamic contentview

Hi,
I'm using the ControlTemplate for my layout in my app which working fine so far. I have defined the parent template in App.xaml and bind the properties for actions in backend ContentPage commands. On each command I dynamically create the Contents (like Grid, StackLoyout etc) and change them to my page content property.
Now in one of my dynamic view I have a button which when clicked, I need to call a method or command from the CurrentPage so that I can change the Content with another page

I have tried the following but without success?
btScan.SetBinding(Button.CommandProperty, new Binding("ScanCommand" ));
btScan.SetBinding(Button.CommandProperty, new Binding("TemplateBinding ScanCommand" ));
btScan.SetBinding(Button.CommandProperty, new Binding("BindingContext.ScanCommand" ));
Any idea how can I bind the button so that it call the page command?

Thanks in advance

Best Answer

  • Jhelumi786Jhelumi786 ✭✭
    Accepted Answer

    I manage to get it solved myself and here is the answer for anyone else benefits.
    Basically I need to pass the reference to the current page and then use the following for binding
    `btnScan.SetBinding(Button.CommandParameterProperty,
    new Binding() { Source = txtArticleCode, Path = "Text" });

            btnScan.SetBinding(Button.CommandProperty,
                new Binding("SearchArticleCommand", source:page ));`
    

    where page is reference of the current/main page

Answers

  • Jhelumi786Jhelumi786 Member ✭✭
    Accepted Answer

    I manage to get it solved myself and here is the answer for anyone else benefits.
    Basically I need to pass the reference to the current page and then use the following for binding
    `btnScan.SetBinding(Button.CommandParameterProperty,
    new Binding() { Source = txtArticleCode, Path = "Text" });

            btnScan.SetBinding(Button.CommandProperty,
                new Binding("SearchArticleCommand", source:page ));`
    

    where page is reference of the current/main page

Sign In or Register to comment.