2011-10-04 2 views
-1

이미지를 체크 표시로 지정하고 싶습니다. WP7에서 가능합니까? 확인란의 모든 속성을 검색했지만 찾지 못했습니다. 감사체크 표시 기호 변경 WP7

답변

0

직접 체크 박스에 이미지를 사용할 수 없지만 표준 Button 객체에 이미지를 사용하고 배경 이미지를가 클릭 할 때마다 변경 될 수 있습니다 :

XAML :

<Button Click="Button_Click" x:Name="btnCheckbox"> 
        <Button.Content> 
         <Image Source="Checkbox_Unselected.png" /> 
        </Button.Content> 
       </Button> 

코드 뒤에 : 분명히

private bool isCheckboxChecked = false; 
private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    isCheckboxChecked = !isCheckboxChecked; 
    this.CheckboxImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri((isCheckboxChecked ? "Checkbox_Selected.png" : "Checkbox_Unselected.png"))); 
} 

오히려 priv에보다 모델의 속성에 isCheckboxChecked을 바인딩도 더 좋은 것 변수를 먹었다.

+0

나는 본다. 당신의 솔루션은 체크 박스 대신 버튼을 사용하는 것입니다. 그러나 실제로는 체크 박스 표시가 문자 V이며 작은 이미지로 변경하려고합니다. 다른 방법이 없다면 코드를 시도해 보겠습니다. 감사합니다 – geeko

+0

ContentTemplate의 이미지를 바꿀 수 있습니다. 완벽하게 수행 할 수 있습니다. –

2

템플릿을 편집하면 쉽게 수정할 수 있습니다. CheckMark이라는 Path 개체를 이미지로 변경하면 황금색이됩니다.

<phone:PhoneApplicationPage.Resources> 
    <Style x:Key="PhoneButtonBase" 
      TargetType="ButtonBase"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}" /> 
     <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" /> 
     <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}" /> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}" /> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}" /> 
     <Setter Property="Padding" Value="10,3,10,5" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ButtonBase"> 
        <Grid Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal" /> 
           <VisualState x:Name="MouseOver" /> 
           <VisualState x:Name="Pressed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" 
                     Storyboard.TargetProperty="Foreground"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneBackgroundBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" 
                     Storyboard.TargetProperty="Background"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneForegroundBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" 
                     Storyboard.TargetProperty="BorderBrush"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneForegroundBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" 
                     Storyboard.TargetProperty="Foreground"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" 
                     Storyboard.TargetProperty="BorderBrush"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" 
                     Storyboard.TargetProperty="Background"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="Transparent" /> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="ButtonBackground" 
           Margin="{StaticResource PhoneTouchTargetOverhang}" 
           Background="{TemplateBinding Background}" 
           BorderBrush="{TemplateBinding BorderBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           CornerRadius="0"> 
          <ContentControl x:Name="ContentContainer" 
              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
              Content="{TemplateBinding Content}" 
              ContentTemplate="{TemplateBinding ContentTemplate}" 
              Foreground="{TemplateBinding Foreground}" 
              Padding="{TemplateBinding Padding}" /> 
         </Border> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <Style x:Key="PhoneRadioButtonCheckBoxBase" 
      BasedOn="{StaticResource PhoneButtonBase}" 
      TargetType="ToggleButton"> 
     <Setter Property="Background" Value="{StaticResource PhoneRadioCheckBoxBrush}" /> 
     <Setter Property="BorderBrush" Value="{StaticResource PhoneRadioCheckBoxBrush}" /> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" /> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}" /> 
     <Setter Property="HorizontalContentAlignment" Value="Left" /> 
     <Setter Property="VerticalContentAlignment" Value="Center" /> 
     <Setter Property="Padding" Value="0" /> 
    </Style> 
    <ImageBrush x:Key="CheckBoxImageBrush" 
       ImageSource="accept.png" /> 
    <Style x:Key="CheckBoxWithImageStyle" 
      BasedOn="{StaticResource PhoneRadioButtonCheckBoxBase}" 
      TargetType="CheckBox"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="CheckBox"> 
        <Grid Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal" /> 
           <VisualState x:Name="MouseOver" /> 
           <VisualState x:Name="Pressed"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" 
                     Storyboard.TargetProperty="Background"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxPressedBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" 
                     Storyboard.TargetProperty="BorderBrush"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxPressedBorderBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckMark" 
                     Storyboard.TargetProperty="Fill"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxCheckBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateMark" 
                     Storyboard.TargetProperty="Fill"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxCheckBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" 
                     Storyboard.TargetProperty="Background"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckBackground" 
                     Storyboard.TargetProperty="BorderBrush"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckMark" 
                     Storyboard.TargetProperty="Fill"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxCheckDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateMark" 
                     Storyboard.TargetProperty="Fill"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneRadioCheckBoxCheckDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" 
                     Storyboard.TargetProperty="Foreground"> 
              <DiscreteObjectKeyFrame KeyTime="0" 
                    Value="{StaticResource PhoneDisabledBrush}" /> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="CheckStates"> 
           <VisualState x:Name="Checked"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CheckMark" 
                     Storyboard.TargetProperty="Visibility"> 
              <DiscreteObjectKeyFrame KeyTime="0"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Visible</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Unchecked" /> 
           <VisualState x:Name="Indeterminate"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateMark" 
                     Storyboard.TargetProperty="Visibility"> 
              <DiscreteObjectKeyFrame KeyTime="0"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Visible</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Grid Margin="{StaticResource PhoneTouchTargetLargeOverhang}"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="32" /> 
           <ColumnDefinition Width="*" /> 
          </Grid.ColumnDefinitions> 
          <Border x:Name="CheckBackground" 
            Width="32" 
            Height="32" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Background="{TemplateBinding Background}" 
            BorderBrush="{TemplateBinding Background}" 
            BorderThickness="{StaticResource PhoneBorderThickness}" 
            IsHitTestVisible="False" /> 
          <Rectangle x:Name="IndeterminateMark" 
             Grid.Row="0" 
             Width="16" 
             Height="16" 
             HorizontalAlignment="Center" 
             VerticalAlignment="Center" 
             Fill="{StaticResource PhoneRadioCheckBoxCheckBrush}" 
             IsHitTestVisible="False" 
             Visibility="Collapsed" /> 
          <Image x:Name="CheckMark" 
            Width="24" 
            Height="18" 
            HorizontalAlignment="Center" 
            VerticalAlignment="Center" 
            IsHitTestVisible="False" 
            Source="accept.png" 
            Stretch="Fill" 
            Visibility="Collapsed" /> 
          <ContentControl x:Name="ContentContainer" 
              Grid.Column="1" 
              Margin="12,0,0,0" 
              HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
              Content="{TemplateBinding Content}" 
              ContentTemplate="{TemplateBinding ContentTemplate}" 
              Foreground="{TemplateBinding Foreground}" 
              Padding="{TemplateBinding Padding}" /> 
         </Grid> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</phone:PhoneApplicationPage.Resources> 
<Grid x:Name="LayoutRoot" 
     Background="Transparent"> 
    <CheckBox IsChecked="True" 
       Style="{StaticResource CheckBoxWithImageStyle}" /> 
</Grid>