0
我正在努力如何切換切換按鈕之間的切換。我想要發生的情況是,如果按下了「是」按鈕,則「否」按鈕將被取消選中,反之亦然。現在,它允許用戶選擇我不想發生的事情。另外,Unchecked的格式不正確,它表示它只能出現在+ =或 - =的左邊,noTBU.Unchecked = true; & yesTBU.Unchecked = true;我不確定我明白這一點?我認爲它返回真或假?如何正確切換切換按鈕與是/否?
// method to handle all Toggle Button tap events
private void ToggleButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
if(yesTBU.IsPressed)
{
// add selected value to text
// disable noTBU toggle
//noTBU.IsChecked = false;
yesTBU.IsChecked = true;
noTBU.Unchecked = true;
if(noTBU.IsPressed)
{
yesTBU.IsChecked = false;
}
}
if(noTBU.IsPressed)
{
// add selected value to text
// disable yesTBU toggle
//yesTBU.IsChecked = false;
noTBU.IsChecked = true;
yesTBU.Unchecked = true;
if(yesTBU.IsPressed)
{
noTBU.IsChecked = false;
}
}
// makes dynamic changes immediately in UI
if(yesTBU.IsChecked == false && noTBU.IsChecked == false)
{
// message box and text font change or Not Specified
disabilityTBL.Text = "Are you disabled? *";
disabilityTBL.Foreground = new SolidColorBrush(Colors.Red);
disabilityTBL.FontWeight = FontWeights.Bold;
}
else
{
// set back to default layout
this.disabilityTBL.ClearValue(TextBlock.ForegroundProperty);
this.disabilityTBL.ClearValue(TextBlock.FontWeightProperty);
this.disabilityTBL.Text = "Are you disabled?";
}
}
謝謝一堆!我會記住這個對象發送者來相應地處理事件。 – TheAmazingKnight