Jason Jason - 1 month ago 12
C# Question

Cannot find IsChecked property in WPF Checkbox

I have a WPF app with a few checkboxes. I am able to set the IsChecked property in XAML, however, when I go to set it programatically, there is no such property. From everything I read, this property (IsChecked) is how I should be setting the value.

The XAML is below:

<Window x:Class="FC.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="FCSX Utility" SizeToContent="WidthAndHeight" ResizeMode="NoResize" Background="WhiteSmoke" Loaded="Window_Loaded">
<Window.InputBindings>
<KeyBinding Key="N"
Modifiers="Control"
Command="ApplicationCommands.Properties" />
<KeyBinding Key="S"
Modifiers="Control"
Command="ApplicationCommands.Print" />
<KeyBinding Key="L"
Modifiers="Control"
Command="ApplicationCommands.PrintPreview" />
<KeyBinding Key="I"
Modifiers="Control"
Command="ApplicationCommands.CancelPrint" />
</Window.InputBindings>
<TabControl Name="tcTabs" SelectionChanged="tcTabs_SelectionChanged">
<TabItem Name="tciClock" Header="Clock">
<StackPanel Name="spClock" Orientation="Vertical" Margin="0">
<Label FontWeight="Bold">Clock</Label>
<StackPanel Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbMinute"></ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Day Of Week</Label>
<ComboBox Name="cbClockDay"></ComboBox>
</StackPanel>
<Button Name="btnSetClockSystemTime" Click="btnSetClockSystemTime_Click">Set To Current System Time</Button>
</StackPanel>


<StackPanel Orientation="Horizontal">
<Label Name ="ckbAlarm1" FontWeight="Bold">Alarm 1</Label>
<CheckBox VerticalAlignment="Center" IsChecked="False"></CheckBox>
</StackPanel>
<StackPanel Name="spAlarm1" Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbAlarm1StartHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbAlarm1StartMinute"></ComboBox>
<Label>Duration</Label>
<ComboBox Name="cbAlarm1DurationHour"></ComboBox>
<Label>hrs</Label>
<ComboBox Name="cbAlarm1DurationMinute"></ComboBox>
<Label>min</Label>
</StackPanel>
<Label>Days:</Label>
<StackPanel Orientation="Horizontal" Margin="10">
<CheckBox Name="ckbAlarm1Mon">Mon</CheckBox>
<CheckBox Name="ckbAlarm1Tues">Tue</CheckBox>
<CheckBox Name="ckbAlarm1Wed">Wed</CheckBox>
<CheckBox Name="ckbAlarm1Thu">Thu</CheckBox>
<CheckBox Name="ckbAlarm1Fri">Fri</CheckBox>
<CheckBox Name="ckbAlarm1Sat">Sat</CheckBox>
<CheckBox Name="ckbAlarm1Sun">Sun</CheckBox>
</StackPanel>
</StackPanel>

<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold">Alarm 2</Label>
<CheckBox Name="ckbAlarm2" VerticalAlignment="Center"></CheckBox>
</StackPanel>
<StackPanel Name="spAlarm2" Orientation="Vertical" Margin="10">
<StackPanel Orientation="Horizontal" Margin="10">
<Label>Start Time</Label>
<ComboBox Name="cbAlarm2StartHour"></ComboBox>
<Label>:</Label>
<ComboBox Name="cbAlarm2StartMinute"></ComboBox>
<Label>Duration</Label>
<ComboBox Name="cbAlarm2DurationHour"></ComboBox>
<Label>hrs</Label>
<ComboBox Name="cbAlarm2DurationMinute"></ComboBox>
<Label>min</Label>
</StackPanel>
<Label>Days:</Label>
<StackPanel Orientation="Horizontal" Margin="10">
<CheckBox Name="ckbAlarm2Mon">Mon</CheckBox>
<CheckBox Name="ckbAlarm2Tues">Tue</CheckBox>
<CheckBox Name="ckbAlarm2Wed">Wed</CheckBox>
<CheckBox Name="ckbAlarm2Thu">Thu</CheckBox>
<CheckBox Name="ckbAlarm2Fri">Fri</CheckBox>
<CheckBox Name="ckbAlarm2Sat">Sat</CheckBox>
<CheckBox Name="ckbAlarm2Sun">Sun</CheckBox>
</StackPanel>
</StackPanel>
<Button>Apply</Button>
</StackPanel>
</TabItem>
<TabItem Name="tciTrigger" Header="Triggering">
<StackPanel Name="spTrigger" Orientation="Vertical">
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Trigger Options</Label>
<StackPanel Margin="10">
<Label>Reset Delay</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Arm Delay</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Take Delay A</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
<Label>Take Delay B</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Trigger Sources</Label>
<CheckBox>Internal Motion Sensor</CheckBox>
<CheckBox>External Sensor</CheckBox>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10">
<Label FontWeight="Bold">Pre-Trigger Options</Label>
<CheckBox>Enable Pre-Trigger</CheckBox>
<StackPanel Margin="10">
<RadioButton>Pre-Trigger on Internal</RadioButton>
<RadioButton>Pre-Trigger on External</RadioButton>
<Label>Pre-Tigger Reset Time</Label>
<StackPanel Orientation="Horizontal">
<TextBox Width="100"></TextBox>
<Label>ms</Label>
</StackPanel>
</StackPanel>
</StackPanel>

</StackPanel>
</TabItem>
<TabItem Name="tciDebug" Header="Debug" Visibility="Collapsed">
<StackPanel Orientation="Vertical" Margin="10">
<Label>Command Line Output</Label>
<TextBlock TextWrapping="WrapWithOverflow"></TextBlock>
</StackPanel>
</TabItem>
<TabItem Header="FW Update">
<StackPanel Orientation="Vertical" Margin="10">
<TextBlock Margin="5" FontSize="14">Welcome!</TextBlock>
<TextBlock Margin="5" FontSize="14">This utility is used to update the firmware of your FC device.</TextBlock>
<TextBlock Margin="5" FontSize="14">Please follow the steps below:</TextBlock>
<Border Margin="2" BorderBrush="Black" BorderThickness="1" Background="White">
<StackPanel Orientation="Vertical" Margin="10,10,10,10" Background="White">

<Image Name="imgUpdate" Source="/FC-Update;component/Update.png" Width="450" Margin="10" Visibility="Visible" />
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" Name="lblStep1">Step 1: Connect your FC to the USB port and place<LineBreak/> the jumper in the right position.</TextBlock>
<TextBlock Name="lblStep1Done" Visibility="Collapsed">[DEVICE DETECTED]</TextBlock>
</StackPanel>
<StackPanel Margin="5" Orientation="Horizontal">
<TextBlock Margin="0,0,15,0" Name="lblStep2">Step 2: Power off the FCand power it back on.<LineBreak/>You should NOT hear any tones but the LED should be lit.<LineBreak/>When done click the 'Continue' button -></TextBlock>
<TextBlock Name="lblStep2Done" Visibility="Collapsed">[DONE]</TextBlock>
<Button Name="btnStep2Continue" Click="btnStep2Continue_Click" Visibility="Hidden" Padding="10,2,10,2" Height="30">Continue</Button>
</StackPanel>

<TextBlock Margin="5" Name="lblStep3">
Step 3: Click 'Choose Firmware Update...', then navigate to the provided .bin firmware update file.<LineBreak/>
After you select the file and click 'Open', the update will start automatically.
</TextBlock>

<Button Name="btnGo" Width="200" Height="30" Margin="10,10,10,5" HorizontalAlignment="Center" HorizontalContentAlignment="Center" IsEnabled="False" Click="btnGo_Click">Choose Firmware Update...</Button>
<TextBlock Name="lblConnect" Foreground="Red" HorizontalAlignment="Center" Visibility="Visible">The 'Choose Firmware Update...' button will only be enabled when<LineBreak/> your FC is connected via the USB cable and has been reset.</TextBlock>

<TextBlock Name="lblPleaseWait" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="OrangeRed" FontWeight="Bold">Please wait...</TextBlock>
<ProgressBar Name="prgMain" Width="200" Height="25" Margin="10,10,10,10" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Visibility="Collapsed" Minimum="0" Maximum="100"></ProgressBar>
<TextBlock Name="lblResetWait" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Green">The firmware update was downloaded and your device was reset.<LineBreak/>Please keep this window open as we wait to make sure it re-connects...</TextBlock>
<TextBlock Name="lblSuccess" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Green">The firmware update was successful and your device re-connected!<LineBreak/>Please complete Step 4 and then close this window.</TextBlock>

<TextBlock Margin="5" Name="lblStep4">
Step 4: Once the update completes successfully,<LineBreak/>remove the jumper and unplug the USB cable.
</TextBlock>

<TextBlock Name="lblError" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Red">The firmware update was NOT successful.</TextBlock>
<TextBlock Name="lblErrorMessage" HorizontalAlignment="Center" Visibility="Collapsed" Foreground="Red" />

<Image Name="imgNoUpdate" Source="/FC-Update;component/NoUpdate.png" Width="450" Margin="10" Visibility="Collapsed" />

<TextBlock Name="lblAllowLuminary" HorizontalAlignment="Center" Visibility="Collapsed" Background="Red" Foreground="White" Margin="10">Will Allow Luminary EPT Devices. Press Ctrl-L Again to Disallow.</TextBlock>

</StackPanel>
</Border>

</StackPanel>
</TabItem>
</TabControl>
</Window>




if (Regex.Matches(alarm1Data.ToString(), "ALARM 1 DISABLED").Count == 1)
{
spAlarm1.IsEnabled = false;
// ckbAlarm1.IsChecked = false; // <--- property not found
}




Answer
<Label Name ="ckbAlarm1" FontWeight="Bold">Alarm 1</Label>

ckbAlarm1 is a LABEL !!

Comments