Reputation: 105
I am trying to achieve a task that bugs me a bit. I have 2 buttons on 2 different pages, I want to achieve this; when pressing on the button situated on the second page, to change the background colour of the button situated on the first page. Example: First Page:
<Stacklayout>
<Button Text="Task 1"
x:Name = "firstPage"
BackgroundColor = "Red" />
</Stacklayout>
SecondPage:
<Stacklayout>
<Button Text="Completed"
x:Name = "secondPage"
Clicked = "ChangeColourForFirst" />
</Stacklayout>
Upvotes: 0
Views: 65
Reputation: 18861
The simplest solution is to use MessagingCenter to send notification when clicking the button .
public MainPage()
{
InitializeComponent();
MessagingCenter.Subscribe<Object, Color>(this, "changeColor", (arg,color) => {
firstPage.BackgroundColor = color;
});
}
private void ChangeColourForFirst(object sender, EventArgs e)
{
MessagingCenter.Send<Object, Color>(this, "changeColor", Color.Red); // send the bgcolor that you want to change
}
Upvotes: 1