Change Styles with C# Code

Feb 22, 2012 at 9: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">
                    <ControlTemplate TargetType="Core:Timeline">
                        <Grid x:Name="MainLayout">

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


Thanks in advance for any help!

Feb 23, 2012 at 1: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