Click here to Skip to main content
15,881,882 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: combining a textblock and textblock into one control Pin
Abhinav S24-Mar-12 0:25
Abhinav S24-Mar-12 0:25 
QuestionPrism and Login Page problem Pin
gio_ab23-Mar-12 3:25
gio_ab23-Mar-12 3:25 
AnswerRe: Prism and Login Page problem Pin
Abhinav S23-Mar-12 17:27
Abhinav S23-Mar-12 17:27 
QuestionWPF C1Flexgrid Pin
Greeshma M J22-Mar-12 20:24
Greeshma M J22-Mar-12 20:24 
AnswerRe: WPF C1Flexgrid Pin
RugbyLeague23-Mar-12 6:51
RugbyLeague23-Mar-12 6:51 
GeneralRe: WPF C1Flexgrid Pin
Greeshma M J25-Mar-12 18:26
Greeshma M J25-Mar-12 18:26 
QuestionUpload images to Server Pin
sudheesh kumar s22-Mar-12 2:51
sudheesh kumar s22-Mar-12 2:51 
QuestionExpander Styling Question Pin
Kevin Marois20-Mar-12 14:13
professionalKevin Marois20-Mar-12 14:13 
The XAML's a bit long here, so please bear with me.

I have styled an expander to look like this[^].

I am very new to styling, so I could use some help. When the expander is collaped I want the rectangle and arrow to be gray. When expanded, I'd like to change the color to orange. I would also like to redraw the arrows facing up.

I got the idea from the expanders here[^].

I really don't know how to go about doing this. Could someone point me in the right direction?

The XAML is

<Window.Resources>

    <Color x:Key="Color1">Gray</Color>
    <Color x:Key="Color2">SlateGray</Color>
    <Color x:Key="Color3">DarkSlateGray</Color>
    <Color x:Key="HeaderGradientBrush1">DarkGray</Color>
    <Color x:Key="HeaderGradientBrush2">White</Color>

    <SolidColorBrush x:Key="ToggleButtonEllipseBorderBrush" Color="{StaticResource Color1}" />
    <SolidColorBrush x:Key="ToggleButtonArrowBrush" Color="{StaticResource Color2}" />
    <SolidColorBrush x:Key="ToggleButtonRectangleBrush" Color="{StaticResource Color2}" />
    <SolidColorBrush x:Key="ToggleButtonBackgroundBrush" Color="Transparent" />
    <SolidColorBrush x:Key="ContentAreaBackgroundBrush" Color="Transparent" />
    <SolidColorBrush x:Key="ExpanderBorderBrush" Color="{StaticResource Color1}" />
    <SolidColorBrush x:Key="ExpanderHeaderTextColor" Color="{StaticResource Color3}" />
    <LinearGradientBrush x:Key="headerGradientBrush"
                            EndPoint="0.504,1.5"
                            StartPoint="0.504,0.03">
        <GradientStop Color="{StaticResource HeaderGradientBrush1}" Offset="0" />
        <GradientStop Color="{StaticResource HeaderGradientBrush2}" Offset="0.567" />
    </LinearGradientBrush>

    <!--Control template for the Toggle Button-->
    <ControlTemplate x:Key="ExpanderToggleButton"
                        TargetType="{x:Type ToggleButton}">

        <Grid Width="16"
                Height="16">

            <Path Stroke="{StaticResource ToggleButtonArrowBrush}"
                    Data="M 3,4 l 5,5 5,-5" />

            <Path Stroke="{StaticResource ToggleButtonArrowBrush}"
                    Data="M 3,7 l 5,5 5,-5" />

            <ContentPresenter VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                Content="{TemplateBinding Content}" />

        </Grid>

    </ControlTemplate>

    <!-- Expander style -->
    <Style TargetType="Expander">

        <Setter Property="Foreground"
                Value="{StaticResource ExpanderHeaderTextColor}" />
        <Setter Property="Template">
            <Setter.Value>

                <!-- Control template for Expander -->
                <ControlTemplate TargetType="Expander">
                    <Grid>
                            
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Name="ContentRow"
                                            Height="0" />
                        </Grid.RowDefinitions>
                            
                        <!--Header Area-->
                        <Border Name="Border"
                                Grid.Row="0"
                                Background="{StaticResource headerGradientBrush}"
                                BorderBrush="{StaticResource ExpanderBorderBrush}"
                                BorderThickness="1">

                            <Grid>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="20" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="20" />
                                </Grid.ColumnDefinitions>

                                <!--Rectangle in the header-->
                                <Border Grid.Row="0"
                                        Background="{StaticResource ToggleButtonRectangleBrush}"
                                        BorderBrush="{StaticResource ExpanderBorderBrush}"
                                        Margin="-4,2,2,2"
                                        Width="10"/>
                                        
                                    <!-- The following puts the toggle button in the right hand column, just like I want! -->
                                <ToggleButton Grid.Column="2"
                                                IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                OverridesDefaultStyle="True"
                                                Template="{StaticResource ExpanderToggleButton}"
                                                Background="{StaticResource ToggleButtonBackgroundBrush}" />

                                <ContentPresenter Grid.Column="1"
                                                    Margin="5"
                                                    ContentSource="Header"
                                                    RecognizesAccessKey="True" />
                            </Grid>

                        </Border>
                            
                        <!--Content Area-->
                        <Border Name="Content"
                                Grid.Row="1"
                                Background="{StaticResource ContentAreaBackgroundBrush}"
                                BorderBrush="{StaticResource ExpanderBorderBrush}"
                                BorderThickness="1,0,1,1"
                                CornerRadius="0,0,3,3">

                            <ContentPresenter Margin="4" />

                        </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="{StaticResource ExpanderBorderBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                    
                </ControlTemplate>
                    
            </Setter.Value>
                
        </Setter>
            
    </Style>
        
</Window.Resources>

Thank you.

Everything makes sense in someone's mind

AnswerRe: Expander Styling Question Pin
Varsha Ramnani21-Mar-12 0:49
professionalVarsha Ramnani21-Mar-12 0:49 
GeneralRe: Expander Styling Question Pin
Abhinav S21-Mar-12 4:14
Abhinav S21-Mar-12 4:14 
GeneralRe: Expander Styling Question Pin
Kevin Marois21-Mar-12 7:25
professionalKevin Marois21-Mar-12 7:25 
QuestionWPF Path Pin
Kevin Marois20-Mar-12 8:44
professionalKevin Marois20-Mar-12 8:44 
AnswerRe: WPF Path Pin
Pete O'Hanlon20-Mar-12 11:42
mvePete O'Hanlon20-Mar-12 11:42 
GeneralRe: WPF Path Pin
Kevin Marois20-Mar-12 11:44
professionalKevin Marois20-Mar-12 11:44 
GeneralRe: WPF Path Pin
Kevin Marois20-Mar-12 11:56
professionalKevin Marois20-Mar-12 11:56 
GeneralRe: WPF Path Pin
Pete O'Hanlon20-Mar-12 12:23
mvePete O'Hanlon20-Mar-12 12:23 
AnswerRe: WPF Path Pin
Abhinav S21-Mar-12 4:13
Abhinav S21-Mar-12 4:13 
QuestionBind To Command On ViewModel Pin
Kevin Marois19-Mar-12 13:46
professionalKevin Marois19-Mar-12 13:46 
AnswerRe: Bind To Command On ViewModel Pin
Pete O'Hanlon20-Mar-12 5:28
mvePete O'Hanlon20-Mar-12 5:28 
GeneralRe: Bind To Command On ViewModel Pin
Kevin Marois20-Mar-12 5:55
professionalKevin Marois20-Mar-12 5:55 
GeneralRe: Bind To Command On ViewModel Pin
Pete O'Hanlon20-Mar-12 6:05
mvePete O'Hanlon20-Mar-12 6:05 
Questionslverlight 3.0 Pin
manivinof519-Mar-12 1:47
manivinof519-Mar-12 1:47 
AnswerRe: slverlight 3.0 Pin
Richard MacCutchan19-Mar-12 1:50
mveRichard MacCutchan19-Mar-12 1:50 
GeneralRe: slverlight 3.0 Pin
manivinof519-Mar-12 1:54
manivinof519-Mar-12 1:54 
GeneralRe: slverlight 3.0 Pin
Pete O'Hanlon19-Mar-12 2:00
mvePete O'Hanlon19-Mar-12 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.