Silverlight 禁用元素上的事件

Silverlight 禁用元素上的事件,silverlight,windows-phone-7,xaml,windows-phone-8,Silverlight,Windows Phone 7,Xaml,Windows Phone 8,我遇到了一个问题,一些元素放在其他元素中会把事件搞砸,比如: 我有扩展器的代码: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Expander"> <Style TargetType="lo

我遇到了一个问题,一些元素放在其他元素中会把事件搞砸,比如:

我有扩展器的代码:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Expander">
<Style TargetType="local:Expander">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:Expander">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ViewStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Expanded">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="ContentScaleTransform"
                                    Storyboard.TargetProperty="ScaleY" To="1" Duration="0"/>

                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Collapsed">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="ContentScaleTransform"
                                    Storyboard.TargetProperty="ScaleY" To="0" Duration="0"/>

                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border BorderBrush="#FFCAADAD"
                    BorderThickness="1"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid  Background="#FFDBDBDB" Margin="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="80"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <ContentPresenter Grid.Column="0" HorizontalAlignment="Center" Grid.ColumnSpan="2" VerticalAlignment="Center" Content="{TemplateBinding HeaderContent}" Canvas.ZIndex="1"/>
                                <ToggleButton Grid.Column="0" Margin="10,0,0,0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" RenderTransformOrigin="0.5,0.5" x:Name="ExpandCollapseButton">
                                    <ToggleButton.Template>
                                        <ControlTemplate>
                                            <Grid>
                                                <VisualStateManager.VisualStateGroups>
                                                    <VisualStateGroup x:Name="ViewStates">
                                                        <VisualStateGroup.Transitions>
                                                            <VisualTransition GeneratedDuration="0:0:0.0"/>
                                                        </VisualStateGroup.Transitions>
                                                        <VisualState x:Name="Checked">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName="RotateButtonTransform" Storyboard.TargetProperty="Angle" To="180" Duration="0"/>
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name="Unchecked">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName="RotateButtonTransform" Storyboard.TargetProperty="Angle" To="0" Duration="0"/>
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                </VisualStateManager.VisualStateGroups>
                                                <Rectangle HorizontalAlignment="Stretch" Height="80" Fill="#FFDBDBDB"/>
                                                <Path RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" VerticalAlignment="Center" Data="M2,3L9,10 16,3" Stroke="Black" StrokeThickness="6" Fill="#FFDBDBDB">
                                                    <Path.RenderTransform>
                                                        <RotateTransform x:Name="RotateButtonTransform"/>
                                                    </Path.RenderTransform>
                                                </Path>
                                            </Grid>
                                        </ControlTemplate>
                                    </ToggleButton.Template>

                                </ToggleButton>
                            </Grid>
                            <ContentPresenter Grid.Row="1" Margin="0" Content="{TemplateBinding Content}" x:Name="Content">
                                <ContentPresenter.RenderTransform>
                                    <ScaleTransform x:Name="ContentScaleTransform"/>
                                </ContentPresenter.RenderTransform>
                            </ContentPresenter>
                        </Grid>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

问题就在这里:

<ContentPresenter Grid.Column="0" HorizontalAlignment="Center" Grid.ColumnSpan="2" VerticalAlignment="Center" Content="{TemplateBinding HeaderContent}" Canvas.ZIndex="1"/>

它位于我的切换按钮顶部,因此文本可见,问题是:

当我点击扩展器时,如果我点击文本所在的位置-扩展器不会展开,如果我不触摸文本,但只是空字段,它就会展开。这意味着正在触发文本点击事件。

有没有办法禁用此功能


我曾尝试将Contentpresenter放入按钮,但它没有看到出价-我不知道如何解决此问题,可能还有其他选项?

设置文本属性
ishitestvisible=false