我有以下问题:我必须在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>
答案 0 :(得分: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
我还建议您了解命令,以及在单击按钮时如何绑定到命令以执行操作。