C#-Accessing .xaml created checkbox/listbox

34 Views Asked by At

Is there a way to verify if checkbox and a specific item in a listbox has been selected, when it was created in .xaml?

I am trying to access these elements from a different class rather than the ViewModel.

I want to be able to do something as follows;

if (First_CheckBox.Ischecked && LocationBox.SelectedItem == "FirstValue")
{
   do something;
}
else
{
   do something else;
}

.XAML Code:

<CheckBox x:Name="First_CheckBox" IsChecked="{Binding Check, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" Content="Integral "/>
<ListBox x:Name="LocationBox" ItemsSource="{Binding LocationList}" SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" Margin="0,5"  Width="100" HorizontalAlignment="Left" BorderThickness="1" Background="#FFF0ECEC">

Current Code:

namespace ValueClearanceCalculator.ViewModels
{
    class MainWindowViewModel : CommonBase
    {
    public delegate void PropertyChangedHandler(object obj);
    public static event PropertyChangedHandler MainVMPropertyChanged = delegate { };

    public MainWindowViewModel()
    {
        CalculateAndDrawPatternCommand = new CalculatePatternCommand(this);
    }
    private public bool _Check;
    public bool Check
    {
        get
        {
            return _Check;
        }
        set
        {
            _Check = value;
            RaisePropertyChanged("Check");
            _C = _A;
            double temp;
            bool result = double.TryParse(_C, out temp);
            if (result == false) { MessageBox.Show("Can Not Convert A to C"); }
            else { FrontPanelVariables.C = temp * 25.4; }
            RaisePropertyChanged("C");
            _F = ".157";
            FrontPanelVariables.F = .157;
            RaisePropertyChanged("F");
        }
    }
0

There are 0 best solutions below