0

有没有办法验证复选框和列表框中的特定项目是否已被选中,当它在.xaml 中创建时?

我试图从不同的类而不是 ViewModel 访问这些元素。

我希望能够做以下事情;

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

.XAML 代码:

<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">

当前代码:

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");
        }
    }
4

0 回答 0