Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:21:29+00:00 2026-06-07T13:21:29+00:00

I’m working in wpf application i made a checkbox in the XAML, then my

  • 0

I’m working in wpf application i made a checkbox in the XAML, then my code calls a function in a class and in this function there is an if condition where its checking on whether the checkbox is checked or not but the checkbox is not seen in this class, so how to do this?

Many thanks

EDIT:

Here are the steps I did:
I created the ViewModel class under the same project of KinectSkeleton as shown:
ViewModel class:

public class ViewModel
{
    public bool IsChecked { get; set; }
    public bool is_clicked { get; set; }
}

and in the KinectSkeleton I defined a property as shown:

public static readonly DependencyProperty ViewModelProperty =
           DependencyProperty.Register("ViewModelH", typeof(ViewModel), typeof(KinectSkeleton), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  

public ViewModel ViewModelH
{
    get => (ViewModel)GetValue(ViewModelProperty);
    set => SetValue(ViewModelProperty, value);
}

and the code of the checkbox and button in the KinectWindow.xaml is:

<Button Content="Calibrate" Height="24" x:Name="Calibrate" x:FieldModifier="public" Width="90" Click="Calibrate_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" DockPanel.Dock="Left" Panel.ZIndex="0" Padding="0" VerticalAlignment="Center" />
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=IsChecked}" Content="AngleDifference" Height="22" x:Name="AngleDifference" x:FieldModifier="public" Width="117" Checked="AngleDifference_Checked" Unchecked="AngleDifference_Unchecked" HorizontalAlignment="Left" VerticalAlignment="Center" Panel.ZIndex="1" HorizontalContentAlignment="Left" />

And in the KinectSkeleton where I want to check the value of the checkbox I write:

    if (this.ViewModelH.IsChecked == false)
    // if(f.is_chekced == false)
    {
        // do something
    }

now I want to know what to write in the is_checked event of the checkbox and is_clicked of the button? also, is there anything missing in my above steps as I feel that till now the Kinect skeleton property is not bound to the checkbox is_checked value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:21:30+00:00Added an answer on June 7, 2026 at 1:21 pm

    Using the following XML you can define a control as a public field on the class to be able to access it from other classes:

    <CheckBox x:Name="myCheckBox" x:FieldModifier="public" />
    

    Now you can access the field directly in code:

    if (win.myCheckBox.IsChecked.Value)
    {
        // ...
    }
    

    I agree with H.B., though, that using the MVVM pattern is a better way to do it. Other parts of your code shouldn’t be aware of your UI or directly access it.

    EDIT:

    With the MVVM approach you should first define your view model class:

    public class ViewModel
    {
        public bool IsChecked { get; set; }
    }
    

    Then you set an instance of this class as DataContext:

    • either in code, e.g. window constructor:
    public MyWindow()
    {
        InitializeComponent();
        DataContext = new ViewModel();
    }
    
    • or in XAML, e.g. App.xaml:
    <Application x:Class="WpfApplication2.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:vm="clr-namespace:WpfApplication2"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
            <vm:ViewModel x:Key="ViewModel" />
        </Application.Resources>
    </Application>
    

    Now you can bind your CheckBox to a property in ViewModel:

    <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" />
    

    All that’s left is to pass the ViewModel instance to your OnRender function. It is stored in the DataContext property of your window.

    EDIT 2:

    BTW: You really should have asked that before you accepted the answer.

    I’m not sure what you are trying to attempt with the is_clicked property. To set this flag when the button is clicked, you need a Command:

    public class CalibrateCommand : ICommand
    {
        private ViewModel viewModel;
    
        public CalibrateCommand(ViewModel viewModel)
        {
            this.viewModel = viewModel;
        }
    
        public void Execute(object parameter)
        {
            viewModel.IsClicked = true;
        }
    
        public bool CanExecute()
        {
            return true;
        }
    }
    

    You add an instance of this command to your view model:

    public class ViewModel
    {
        public bool IsChecked { get; set; }
        public bool IsClicked { get; set; }
        public ICommand CalibrateCommand { get; set; }
    
        public ViewModel()
        {
            CalibrateCommand = new CalibrateCommand(this);
        }
    }
    

    You bind it to the button like this:

    <Button Content="Calibrate" Height="24" x:Name="Calibrate" x:FieldModifier="public" Width="90" Click="Calibrate_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalAlignment="Left" DockPanel.Dock="Left" Panel.ZIndex="0" Padding="0" VerticalAlignment="Center" Command="{Binding CalibrateCommand}" />
    

    You don’t need to handle any events of the CheckBox and the Button, everything is handled by the binding.

    If you added a dependency property to KinectSkeleton you should bind it to the view model:

    <kt:KinectSkeleton ViewModelH="{Binding}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.