question

MarkusNottbohm-2313 avatar image
0 Votes"
MarkusNottbohm-2313 asked MarkusNottbohm-2313 answered

Click event used in code behind and also in viewmodel

Hi,

I need some help on the following:

I need to have the button event fire in code behind, but need also some data updates in the viewmodel.

I see now two options:

  1. Write the data in the code behind into label and have the value than as binding in the viewmodel

or

  1. Have the button event fired in a button Clicked event for code behind and also as Command in viewmodel:

Clicked="SfButton_Clicked"
Command="{Binding ClickClear_BSP}"

I tested both options, both are working, but what would be the best option and is there maybe a better option to go?

Thanks,

Markus

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

Both of solution are Ok, I refer to use the second option, it is direct based on your needs. Note: If you mind the execute operation, based on my test, ClickClear_BSP will execute firstly, then SfButton_Clicked executed. Here is my test screenshot.

88887-image.png

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (4.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkusNottbohm-2313 avatar image
0 Votes"
MarkusNottbohm-2313 answered

Thank you Leon Lu.

This is also my preferred way, even both of the options are more or less workaround solutions.

Thanks,

Markus

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.