user440096
user440096

Reputation:

Setting the value of objects in XAML from the .xaml.cs file

I can declare a checkbox in XAML like so

<CheckBox Content="Accepted" Height="71" Name="checkBox" />

When this screen loads I want to check the data associated with the screen and set it if the box is checked, or it its not checked.

public TripDetails()
{
   string yesString = "YES";
    if (String.ReferenceEquals(meeting.accepted, yesString))
    {
        // set the checkbox
    }
    this.DataContext = this;
    InitializeComponent();
}

What I cannot understand is how to set the checkbox declared in the XAML from within my cooresponding xaml.cs file.

Could somebody please advise what should go where my // set the checkbox is.

Many Thanks, -Code

Upvotes: 0

Views: 369

Answers (1)

Steve Danner
Steve Danner

Reputation: 22198

Unless I'm missing something...since you've named the CheckBox "checkBox", it should just be

this.checkBox.IsChecked = !this.checkBox.IsChecked;

Upvotes: 1

Related Questions