Thanks Walter that did it. In my case I added the style to a resource file.
In order to refrence the style from c#, I had to add a reference to the file
in the window's xaml like this:
<Window.Resources>
<ResourceDictionary Source="Dictionary1.xaml" />
</Window.Resources>
Here's the style in Dictionary1.xaml:
<Style x:Key="ThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Ellipse Width="15" Height="15" Stroke="DarkSlateGray"
StrokeThickness="0.5">
<Ellipse.Fill >
<SolidColorBrush Color="DarkBlue" Opacity="0.2"></SolidColorBrush>
</Ellipse.Fill>
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect Color="Black" Direction="320"
ShadowDepth="5" Softness="0.5" Opacity="0.2" />
</Ellipse.BitmapEffect>
</Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and here's the c# that used it:
Thumb tb = new Thumb();
Canvas.SetLeft(tb, 100);
Canvas.SetTop(tb, 100);
myCanvas.Children.Add(tb);
tb.Style = (Style)this.FindResource("ThumbStyle");
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:a4****************@TK2MSFTNGHUB02.phx.gbl...
As you may already have known, you could still define the style (template)
in XAML. Then you could use FindResource (method of FrameworkElement) to
load the resource and apply it to the Thumb object that you've created
using code:
<Grid Name="grid1">
<Grid.Resources>
<Style x:Key="ThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Ellipse Width="10" Height="5" Stroke="Blue" Fill="Blue"
StrokeThickness="2"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Thumb Name="thumb1" Height="10" Width="10" Opacity=".4"
Background="MediumBlue">
</Thumb>
</Grid>
Code:
thumb1.Style = (Style) grid1.FindResource("ThumbStyle");
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.