0

我有以下问题:我必须在 Expander 标题中添加几个额外的按钮(以更改扩展器内容的呈现方案 - 图形或表格)。但问题是,当我按下这些按钮时,Expander 正在折叠或展开(我只想改变内容)。我记得网络开发中的泡沫事件。我为 CancelBubble 找到了以下解决方案: e.Handled = true; 但这无济于事

<Expander x:Name="xpdNumberDevices">
    <Expander.Header >
        <Border Background="#E5E5E5">
            <StackPanel Width="605" Height="40" Orientation="Horizontal" HorizontalAlignment="Center">
                <Label Foreground="Black" Content="Number of Devices" 
                        HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,0,0,0" FontSize="14" />
                <Image x:Name="imgGraphNumberDevices" Height="24" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="380,0,0,0"
                        MouseLeftButtonUp="btnNumDeviceGraph_Click">
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Setter Property="Source" Value="/Pictures/graph_button.png"/>
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Source" Value="/Pictures/graph_button_over.png"/>
                                    </Trigger>
                               </Style.Triggers>
                         </Style>
                     </Image.Style>    
                </Image>
                <Image Height="24" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,0,0"
               MouseLeftButtonUp="btnNumDeviceTable_Click">
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Setter Property="Source" Value="/Pictures/table_button.png"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Source" Value="/Pictures/table_button_over.png"/>
                                </Trigger>
                             </Style.Triggers>
                         </Style>
                     </Image.Style>    
                 </Image>
             </StackPanel>
          </Border>
      </Expander.Header>
      <my:Chart Name="crtDeviceNumberChart" Title="Number of Devices" VerticalAlignment="Top" Margin="20,5,0,0" Height="280" Width="600" BorderBrush="#FFE5E5E5">
          <my:BarSeries Title="Devices" DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}" IsSelectionEnabled="True" />
      </my:Chart>                            
  </Expander>
4

1 回答 1

0

既然您将图像视为按钮,为什么不将其设为带有图像的按钮呢?作为测试,如果您用按钮替换图像,您会看到单击标题上的按钮不会展开/折叠Expander.

您可以只修改按钮的模板,它看起来像一个图像:

<Button>
    <Button.Template>
        <ControlTemplate>
            <Border HorizontalAlignment="Center" VerticalAlignment="Center" >
                <Image Source="/Pictures/graph_button.png" Width="24" Height="24"/>
            </Border>
        </ControlTemplate>
    </Button.Template>
</Button

我还建议了解命令以及如何在单击按钮时绑定到命令以执行操作。

于 2013-04-15T12:48:34.730 回答