2014-10-22 3 views
0

아래 라디오 템플릿 컨트롤 템플릿을 사용하고 있습니다. 이 코드에 문제가 있습니다. 알림 라디오 버튼이 선택되어 있지 않은 경우 CheckMark이 접히지 않습니다. 어떤 도움을 주셔서 감사합니다.WPF RadioButton 컨트롤 템플릿 관련 문제

<ControlTemplate x:Key="RadioButtonControlTemplate" TargetType="{x:Type RadioButton}"> 
     <BulletDecorator x:Name="bulletDecorator" SnapsToDevicePixels="True" Background="Transparent"> 
      <BulletDecorator.Bullet> 
       <Grid Width="30" 
       Height="30" > 
        <Ellipse x:Name="Border" 
       Fill="{StaticResource NormalBrush}" 
       StrokeThickness="3" 
       Stroke="{StaticResource NormalBorderBrush}" /> 
        <Ellipse x:Name="CheckMark" 
       Margin="9" 
       Fill="{StaticResource GlyphBrush}" /> 
       </Grid> 
      </BulletDecorator.Bullet> 
      <ContentPresenter Margin="4,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RecognizesAccessKey="True"></ContentPresenter> 
     </BulletDecorator> 
     <ControlTemplate.Triggers> 
      <Trigger Property="IsChecked" Value="False"> 
       <Setter Property="Visibility" TargetName="CheckMark" Value="Collapsed"/> 
      </Trigger> 
      <Trigger Property="HasContent" Value="True"> 
       <Setter Property="FocusVisualStyle"> 
        <Setter.Value> 
         <Style> 
          <Setter Property="Control.Template"> 
           <Setter.Value> 
            <ControlTemplate> 
             <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="14,0,0,0" SnapsToDevicePixels="True"/> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </Setter.Value> 
       </Setter> 
       <Setter Property="Padding" Value="2,0,0,0"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="False"> 
       <Setter Property="Opacity" TargetName="bulletDecorator" Value="0.2"/> 
      </Trigger> 
     </ControlTemplate.Triggers> 
    </ControlTemplate> 
+0

실제로 확인되지 않았 음을 어떻게 알 수 있습니까? 귀하의 코드를 시도하고 실제로 작동합니다. 하지만 적어도 *** 2 개의 라디오 버튼이 필요합니다 ***. 왜냐하면 단 하나의 라디오 버튼 만 사용하면 ***을 한 번 확인해 볼 수 있습니다. 그런 다음 코드를 사용하지 않는 한 UI를 통해 선택을 취소 할 수 없습니다. –

+0

감사합니다. 2 개의 라디오 버튼을 사용하고 있지만 여전히 작동하지 않습니다. 2 개의 라디오 버튼을 사용해 보셨습니까? – codematrix

+1

물론 두 개의 라디오 버튼을 동일한 컨테이너에 배치해야합니다. 그렇지 않으면 두 그룹 모두에 동일한 'GroupName'을 설정해야합니다. –

답변

1

코드가 올바르게 작동합니다. 코드에서 제공하지 않았기 때문에 Brush es를 대체했지만이 기본 예제를 사용하면 RadioButton이 작동하는 것을 볼 수 있습니다 ... 연결이 끊어지기 때문에 라벨을 정렬해야 할 수도 있습니다. '체크 마크'

<ControlTemplate x:Key="RadioButtonControlTemplate" TargetType="{x:Type RadioButton}"> 
    <BulletDecorator x:Name="bulletDecorator" SnapsToDevicePixels="True" Background="Transparent"> 
     <BulletDecorator.Bullet> 
      <Grid Width="30" Height="30"> 
       <Ellipse x:Name="Border" Fill="Red" StrokeThickness="3" Stroke="Black" /> 
       <Ellipse x:Name="CheckMark" StrokeThickness="1" Margin="9" Fill="Green" /> 
      </Grid> 
     </BulletDecorator.Bullet> 
     <ContentPresenter Margin="4,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RecognizesAccessKey="True"></ContentPresenter> 
    </BulletDecorator> 
    <ControlTemplate.Triggers> 
     <Trigger Property="IsChecked" Value="False"> 
      <Setter Property="Visibility" TargetName="CheckMark" Value="Collapsed"/> 
      <Setter Property="Stroke" TargetName="CheckMark" Value="Blue"/> 
     </Trigger> 
     <Trigger Property="HasContent" Value="True"> 
      <Setter Property="FocusVisualStyle"> 
       <Setter.Value> 
        <Style> 
         <Setter Property="Control.Template"> 
          <Setter.Value> 
           <ControlTemplate> 
            <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="14,0,0,0" SnapsToDevicePixels="True"/> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="Padding" Value="2,0,0,0"/> 
     </Trigger> 
     <Trigger Property="IsEnabled" Value="False"> 
      <Setter Property="Opacity" TargetName="bulletDecorator" Value="0.2"/> 
     </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 

... 여기

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> 
    <RadioButton Template="{StaticResource RadioButtonControlTemplate}" Content="Yes" /> 
    <RadioButton Template="{StaticResource RadioButtonControlTemplate}" Content="No" /> 
</StackPanel> 

그것 (무서운 색상 미안)의 모습입니다 :

enter image description here

,