在Silverlight 5中切换按钮IsChecked = true时,无法单击ToggleButton模板内的按钮

时间:2015-05-10 08:07:04

标签: silverlight togglebutton

我遇到了一个试图修复但没有成功的问题。因此,有一个派生自ToggleButton(Silverlight 5)类的EditableToggleButton,它有自己的模板:

<!-- Editable Toggle Button -->

<ControlTemplate x:Key="EditableToggleButtonTemplate"
                 TargetType="customControls:EditableToggleButton">
    <Grid>
        <vsm:VisualStateManager.VisualStateGroups>                
            <vsm:VisualStateGroup x:Name="CommonStates">
                <vsm:VisualState x:Name="Normal" />
                <vsm:VisualState x:Name="MouseOver">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="NormalBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="HoverBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
                <vsm:VisualState x:Name="Pressed">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="NormalBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="PressedBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
                <vsm:VisualState x:Name="Checked">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="NormalBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Duration="0"
                                                       Storyboard.TargetName="PressedBorder"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0"
                                                    Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </vsm:VisualState>
            </vsm:VisualStateGroup>
        </vsm:VisualStateManager.VisualStateGroups>
        <Border x:Name="NormalBorder"
                Margin="1,2,1,2">
            <Button Content="TEST BUTTON" Width="50" />
        </Border>
        <Border x:Name="HoverBorder"
                Visibility="Collapsed"
                Background="#ececec"
                Margin="1,2,1,2">
            <Button Content="TEST BUTTON" Width="50" />
        </Border>           

        <Border x:Name="PressedBorder"
                Visibility="Collapsed"
                Background="#FF807974"
                Margin="1,2,1,2">
            <Button Content="TEST BUTTON" Width="50" />
        </Border>
    </Grid>
</ControlTemplate>

<Style TargetType="customControls:EditableToggleButton">
    <Setter Property="Template"
            Value="{StaticResource EditableToggleButtonTemplate}" />
</Style>

EditableToggleButton类不包含任何逻辑:

public class EditableToggleButton: ToggleButton
{
}

问题是,当EditableToggleButton实例处于检查状态时,&#34; TEST BUTTON&#34;其模板内的按钮无法按下,因此不会触发&#34; OnClick&#34;事件。与此同时,OnMouseHover事件正在发挥作用。我已经分析了ILSpy中ToggleButton代码的IsChecked属性的用法,但没有找到这种行为的答案。你能帮忙让内部按钮可点击吗?谢谢!

0 个答案:

没有答案