2012-04-14 5 views
0

私は最大3つの回答が可能なクイズのアプリケーションを持っています。答えはスタイルに割り当てられたボタンです。すべての解答ボタンは同じクリックイベントを持っている...コントロールに割り当てられているスタイルを特定する方法

Private Sub butAnswer_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs) 
    'An Answer has been clicked 

    Dim butC as Button 
    Dim butS as String = TryCast(sender, Button).Name.ToString() 
    'Cycle through all answers and set style 
    For x = 1 to 3 
     butC = DirectCast(FindName("butAnswer" & x), Button) 
     If butS = "butAnswer" & x.ToString Then 
      butC.Style = DirectCast(FindResource("GlassButtonSelected"), Style) 
     Else 
      butC.Style = DirectCast(FindResource("GlassButton"), Style) 
     End If 
    Next 

End Sub 
ユーザーが「選択」スタイルに答える上の第二の時間をクリックした場合は、「GlassButton」に戻って戻っているように、私は今、これを拡張したい

If butS = "butAnswer" & x.ToString Then 
'Check what style the button has 
    If 'style is GlassButton' Then 
     butC.Style = DirectCast(FindResource("GlassButtonSelected"), Style) 
    Else 
     butC.Style = DirectCast(FindResource("GlassButton"), Style) 
    End If 
Else 
    butC.Style = DirectCast(FindResource("GlassButton"), Style) 
End If 

私の質問はどのようにボタンのスタイルを決定するのですか?

ADDITIONAL UPDATE

ケント、 おかげで、私はWPFに新たなんだと、すべてのこれらの余分なコントロールについては知らなかった... は、私は今、単一の確認や未チェックのトグルボタンに私のボタンを変換していましたすべてのToggleButtonによって使用されるイベントです。私は目標がToggleButtonになるように自分のスタイルを修正しました。私は選択された答えを示すために使用するスタイルを取り除いています。基本的には背景色の変更です。私のチェックされたイベントは...

Private Sub togAnswer_Checked(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs) 
    'togAnswer was clicked.... 
    Dim togC as ToggleButton 
    Dim togS as String = TryCast(sender, ToggleButton).Name.ToString() 
    'Cycle through all answers and set style 
    Dim bc = New BrushConverter() 

    For x = 1 to 3 
     togC = DirectCast(FindName("togAnswer" & x), ToggleButton) 

     If togS = "togAnswer" & x.ToString Then 
          'Set ToggleButton to selected colour 
      togC.Background = DirectCast(bc.ConvertFrom("#AAFF8020"), Brush) 
     Else  
      'Set other ToggleButtons to unselected colour 
      togC.Background = DirectCast(bc.ConvertFrom("#AA000000"), Brush) 
     End If 
    Next 
End Sub 

残念ながらボタンの色は変わりません。どんな考え?

答えて

3

要するに、間違っています。ビヘイビア(2つの状態のいずれかにあるボタン)を識別し、そのビヘイビアの視覚的表現と区別する必要があります。そうすることで、ToggleButtonを使用し、そのIsCheckedプロパティに基づいて外観を変更するだけです。

+0

Kent、ToggleButton(s)へのポインタありがとう。私は変更を提案しましたが、私はまだピクルスのビットです...背景色は変更されません。上記の私の主な質問の詳細を更新してください。何か案は?誰でも.... – Mych

+0

ToggleButton(s)へのポインタありがとう。私は変更を提案しましたが、私はまだピクルスのビットです...背景色は変更されません。上記の私の主な質問の詳細を更新してください。何か案は?誰でも.... – Mych

+0

はToggleButtonの正しい方向に私を指摘しています。私はまだ背景を変えることに関して新しい問題があるが、私の質問に答えている。私はこれを答えとしてマークし、別の質問を提起した – Mych

関連する問題