Click event of Button in content page's custom control (content view) not firing

paul_macpaul_mac Member ✭✭
edited January 16 in Xamarin.Forms

I have a custom control (content view xaml) containing button, label, bindable picker that is rendered in a content page. For the button in the custom control (xaml), I attached a clicked event with a event name and corresponding event handler with that event name in its code-behind (content view xaml.cs). Now, the button and all other contents in content view are rendered properly, but the event handler function is not fired/executed on debugging. Can't I use events in a button from content view, but only content page? Thanks

Best Answers

  • paul_macpaul_mac ✭✭
    edited January 17 Accepted Answer

    @ColeX, thanks very much for the reply

    Now, my problem is solved. Somehow, I had missed the class attribute [XamlCompilation(XamlCompilationOptions.Compile)] on top of class declaration. Very silly mistake..! Even then, the content view's code behind was not fired/executed. Then after closing the solution, rebuilding, running the project, now clicked event fires fine!

    Thanks

Answers

  • paul_macpaul_mac Member ✭✭
    edited January 17 Accepted Answer

    @ColeX, thanks very much for the reply

    Now, my problem is solved. Somehow, I had missed the class attribute [XamlCompilation(XamlCompilationOptions.Compile)] on top of class declaration. Very silly mistake..! Even then, the content view's code behind was not fired/executed. Then after closing the solution, rebuilding, running the project, now clicked event fires fine!

    Thanks

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 17

    I see the button is wrapped in the Grid whose Grid.Row = 1 , but i didn't find the RowDefinitions of its parent Grid , it means there is just only one row, but you set it as second row.

    Try to modify this line

    <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6">
    

    to

    <Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="6">
    
  • paul_macpaul_mac Member ✭✭
    edited January 17

    @ColeX, anyways, thanks very much for your help.

    Can't I use events in a button from content view, but only content page? Thanks

    "You: Definitely not .

    This function work perfectly without any problem on my side"

    I wouldn't have checked it again without your testing... :-)

    So, its possible to use events in a button from content view, not only content page

    Sorry @ColeX, I didnot see your reply, so I edited my comment that had my code

Sign In or Register to comment.