Change Styles with C# Code

Feb 22, 2012 at 8:22 AM

Hi, does anyone know how to change styles programmatically in C#?

 

What I want is to change the ImageSource of the timeline style

        <Style x:Key="TimelineStyleCustom" TargetType="Core:Timeline">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Core:Timeline">
                        <Grid x:Name="MainLayout">


                            <Grid x:Name="HorizontalTemplate" IsHitTestVisible="True" Height="50">
                                <Grid.Background>
                                    <ImageBrush Stretch="Fill" ImageSource="Sound_Wave.jpg"/>
                                </Grid.Background>
                               
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 

Thanks in advance for any help!

Feb 23, 2012 at 12:33 PM

You can get a hold of items in styles by their name. For instance to get access to the HorizontalTemplate you could do:

Grid HorizontalTemplate = (Grid)GetTemplateChild("HorizontalTemplate");
- Loke