Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Silverlight 5中,当切换按钮被选中=true时,无法单击切换按钮模板内的按钮_Silverlight_Togglebutton - Fatal编程技术网

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

在Silverlight 5中,当切换按钮被选中=true时,无法单击切换按钮模板内的按钮,silverlight,togglebutton,Silverlight,Togglebutton,我遇到了一个试图解决但没有成功的问题。因此,有一个派生自具有自己模板的ToggleButton(Silverlight 5)类EditableTogleButton: <!-- Editable Toggle Button --> <ControlTemplate x:Key="EditableToggleButtonTemplate" TargetType="customControls:EditableToggleButton">

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

<!-- 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>

问题是,当EditableTogleButton实例处于选中状态时,无法按下其模板中的“测试按钮”按钮,因此不会触发“OnClick”事件。同时,onmousehave事件正在工作。我分析了ILSpy中ToggleButton代码的IsChecked属性的用法,但没有找到这种行为的答案。你能帮我把里面的按钮按一下吗?谢谢大家!

我忘了在正常状态下添加“测试按钮”工作正常。我不知道为什么它在按下状态下不触发OnClick事件。欢迎使用StackOverflow。您可以编辑您的问题,无需通过评论添加信息。为什么你想在一个按钮里面有一个按钮?你想要实现什么?谢谢你的回答。切换按钮实例具有选中和未选中状态,我需要此功能来打开/关闭某些图形层。同时,图层的名称在切换按钮中显示为其内容。此外,我想添加两个按钮“编辑”和“删除”,以便用户可以编辑或删除图层的名称。因此,我有一个切换按钮和其中的两个按钮,当选中父按钮时,它们不可单击。我通过不是从ToggleButton类而是从ButtonBase类派生并手动实现IsChecked逻辑来修复它。现在可以了。在当前状态下,您的问题对其他用户并没有真正的用处,您找到了实现需求的另一种方法。也许你只是删除了这个问题。否则你就要冒被否决的风险。
public class EditableToggleButton: ToggleButton
{
}