private void BtnRead_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; string register = btn.Name.Substring(12, 2); byte registerParsed = byte.Parse(register, NumberStyles.HexNumber); Screen screen = (Screen)cmbxScreenList.SelectedItem; byte[] data = Connector.Action23GetRegister(screen, registerParsed); BitArray ba = new BitArray(data); for (int pos = 0; pos <= 7; pos++) { ToggleButton btnRegister = FindChild <ToggleButton>(this, "btnRegisterR" + register + "P" + pos); btnRegister.IsChecked = ba[pos]; } }