2013-01-24 55 views
0

我是WPF和XAML編程的初學者。而我的英語不太好。對不起!XAML WPF複選框不顯示何時更改.ischecked屬性

這是我的問題。我想要一個自定義的複選框。它應該只在鼠標結束並且光標應該變爲幫助光標時啓用。

這工作正常!當我在複選框中單擊時,複選框將更改爲.ischeckd = true,並在複選框中顯示litte箭頭。當我再次點擊複選框時,.ischecked屬性更改爲false,但複選框中的小箭頭消失了。到現在爲止還挺好! 但是,當我設置.ischeckd Value Programaticaly時,它不會更改複選框中的小箭頭。因此,該程序的用戶認爲即使.ischecked屬性爲false,該複選框也是「活動的」。希望你明白我的問題...... 這裏是XAML代碼:

</Style> 
    <Storyboard x:Key="StoryboardCheckBox"/> 
    <Style x:Key="CheckBoxStyle1" TargetType="{x:Type CheckBox}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type CheckBox}"> 
        <Grid Margin="0,0,42,0"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal"/> 
           <VisualState x:Name="MouseOver"> 
            <Storyboard> 
             <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="checkBox"> 
              <DiscreteBooleanKeyFrame KeyTime="0" Value="True"/> 
             </BooleanAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="Pressed"/> 
           <VisualState x:Name="Disabled"/> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <CheckBox x:Name="checkBox" Content="Gutschrift" FontSize="13.333" IsEnabled="False" Cursor="Help" Margin="0,0,4.937,0"/> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="" Margin="78.063,9.723,0,0"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

... 一些標貼和按鈕和其他的東西

<CheckBox Content="CheckBox" HorizontalAlignment="Left" Height="23" Margin="29,0,0,44" Grid.Row="1" Style="{DynamicResource CheckBoxStyle1}" VerticalAlignment="Bottom" Width="125" Name="CheckBoxGutschrift" IsChecked="False" DataContext="{Binding}" Checked="CheckBoxGutschrift_Checked" Unchecked="CheckBoxGutschrift_Unchecked" ClickMode="Press" IsTabStop="False" /> 

希望你明白我的問題!非常感謝您的答案,Ruediger

回答

1

你忘了內部複選框的IsChecked財產控件模板綁定:

<CheckBox x:Name="checkBox" IsChecked="{TemplateBinding IsChecked}" ... 
+0

就像一個魅力!非常非常感謝你! – user2006644

相關問題