Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Custom Expander Style => Expand/collapse images are not getting displayed on all the expanders.

$
0
0

Hi,

I have created my own style for Expander and I have put it in UserControl's resources.

I have three expanders. Style is getting applied to all of them but the Images are not getting displayed on all of the expanders.

And when I expand any expander (lets say 1st expander which doesn't have image), image is getting displayed on it and image in other expander disapprear (third expander which had expand image).

Any Ideas?

Expander Style:

<Image Source="..\Images\Expand.ico" VerticalAlignment="Center" HorizontalAlignment="Center" x:Key="expandImage"></Image><Image Source="..\Images\Collapse.ico" VerticalAlignment="Center" HorizontalAlignment="Center" x:Key="collapseImage"></Image><Style TargetType="Expander"><Setter Property="Foreground" Value="White"/><Setter Property="Template"><Setter.Value><!-- Control template for expander --><ControlTemplate TargetType="Expander"><Grid><Grid.Resources></Grid.Resources><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Name="ContentRow" Height="0"/></Grid.RowDefinitions><Border Name="Border" Grid.Row="0" Background="#3B6AA0" BorderBrush="#3B6AA0" BorderThickness="0" CornerRadius="4,4,0,0" ><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition Width="20" /></Grid.ColumnDefinitions><ToggleButton x:Name="toggleButton" Grid.Column="1" Content="{DynamicResource expandImage}" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Background="#6B97C8"/><ContentPresenter Grid.Column="0" Margin="4" ContentSource="Header" RecognizesAccessKey="True" /></Grid></Border><Border Name="Content" Grid.Row="1" Background="#ACC4E0" BorderBrush="#ACC4E0" BorderThickness="0" CornerRadius="0,0,4,4" ><ContentPresenter Margin="0 2 0 0" /></Border></Grid><ControlTemplate.Triggers><Trigger Property="IsExpanded" Value="True"><Setter TargetName="ContentRow" Property="Height"  Value="{Binding ElementName=Content,Path=DesiredHeight}" /><Setter TargetName="Border" Property="BorderBrush" Value="#3B6AA0"/><Setter TargetName ="toggleButton" Property="Content" Value="{DynamicResource collapseImage}" /></Trigger><Trigger Property="IsExpanded" Value="False"><Setter TargetName ="toggleButton" Property="Content" Value="{DynamicResource expandImage}" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

Regards


Ashish Dhyani



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>