473,387 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to change shape of thumb to ellips in wpf

I'm writing a windows app in WPF and want to change the shape of a thumb to
an ellipse. Is this possible? also, the edges of the thumb are beveled.
Is it possible to change this to a flat look and if so, how?

Here's how I'm creating my thumb so far.
Expand|Select|Wrap|Line Numbers
  1. cornerThumb = new Thumb();
  2. // Set some arbitrary visual characteristics.
  3. cornerThumb.Cursor = customizedCursor;
  4. cornerThumb.Height = cornerThumb.Width = 10;
  5. cornerThumb.Opacity = 0.40;
  6. cornerThumb.Background = new SolidColorBrush(Colors.MediumBlue);
Thanks for any input.
--
Jan 9 '07 #1
6 21719
You'll probably get better help in the Avalon newsgroup (or the MSDN
Forums), but yes, it's possible. It's easier to represent in XAML, but what
you want to do is override the visual template with your new visual:

Expand|Select|Wrap|Line Numbers
  1. <Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
  2. <Thumb.Style>
  3. <Style TargetType={x:Type Thumb}>
  4. <Style.Setters>
  5. <Setter Property="Template">
  6. <Setter.Value>
  7. <ControlTemplate TargetType="{x:Type Thumb}">
  8. <Ellipse.../>
  9. </ControlTemplate>
  10. </Setter.Value>
  11. </Setter>
  12. </Style.Setters>
  13. </Style>
  14. </Thumb.Style>
  15. <Thumb.Cursor>
  16. </Thumb.Cursor>
  17. </Thumb>
Jan 9 '07 #2
Thanks Keith. I hope you don't mind that I revised your code a little as
follows:

Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="WindowsApplication1.Window1"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="WindowsApplication1" Height="300" Width="300"[quote]
  5.  
  6. <Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
  7. <Thumb.Style>
  8. <Style TargetType="{x:Type Thumb}">
  9. <Setter Property="Template">
  10. <Setter.Value>
  11. <ControlTemplate TargetType="{x:Type Thumb}">
  12. <Ellipse Width="10" Height="5" Stroke="Blue"
  13. StrokeThickness="2"></Ellipse>
  14. </ControlTemplate>
  15. </Setter.Value>
  16. </Setter>
  17. </Style>
  18. </Thumb.Style>
  19. </Thumb>
  20. </Window>
#Styling and Templating
http://msdn2.microsoft.com/en-us/library/ms745683.aspx
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.
Jan 9 '07 #3
Walter,

This was a good start, but I need to do everything via c# and not xaml. the
link you provided also helped me in that direction, but its still not
working yet. I have a sample with 1 window and 1 button and a resource file
for the thumb's style. Here's the resorce xaml:
Expand|Select|Wrap|Line Numbers
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         
  5.                 >
  6.  
  7. <Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="Thumb"
  8. x:Key="TestRoundThumb" <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="{x:Type Thumb}">
  11. <Ellipse Width="20" Height="15" Stroke="Blue"
  12. StrokeThickness="2"></Ellipse>
  13. </ControlTemplate>
  14. </Setter.Value>
  15. </Setter>
  16. </Style>
  17. </ResourceDictionary>
and here's the code in the button click event:
Expand|Select|Wrap|Line Numbers
  1. private void RoundThumb(object sender, RoutedEventArgs e)
  2. {
  3. Thumb roundThumb = new Thumb();
  4. roundThumb.Height = 15;
  5. roundThumb.Width = 20;
  6. roundThumb.Style = (Style)(this.Resources["TestRoundThumb"]);
  7. myGrid.Children.Add(roundThumb);
  8. }

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:KZ****************@TK2MSFTNGHUB02.phx.gbl...
Thanks Keith. I hope you don't mind that I revised your code a little as
follows:

<Window x:Class="WindowsApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowsApplication1" Height="300" Width="300"
>

<Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
<Thumb.Style>
<Style TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Ellipse Width="10" Height="5" Stroke="Blue"
StrokeThickness="2"></Ellipse>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Thumb.Style>
</Thumb>
</Window>

#Styling and Templating
http://msdn2.microsoft.com/en-us/library/ms745683.aspx
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.
Jan 10 '07 #4
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.

Jan 12 '07 #5
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.

Jan 18 '07 #6
Hi moondaddy,

You probably have seen my reply in your another post regarding this
FindResource question. Anyway, I'm including the reply here again for your
reference:

-----------

When finding a resource, it first checks the current element's Resources
collection (its resource dictionary). If the item is not found, it checks
the parent element, its parent, and so on until it reaches the root
element. At that point, it checks the Resources collection on the
Application object. If it is not found there, it finally checks a system
collection (which contains system-defined fonts, colors, and other
settings). If the item is in none of these collections, it throws an
InvalidOperationException.

Therefore you could simply put resources in App.xaml within
<Application.Resourcesand those resources will be shared by all your code
in the same assembly.

For ResourceDictionary defined in separate .xaml files, you could use
following code to load it:

ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"Dictionary1.xaml", UriKind.Relative);

Then you can use rd["resource_key"] to reference each resource.
-------------

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.

Jan 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: S.W. Rasmussen | last post by:
A trivial (?) question: does anyone know how to change the shape of the cursor in a RichTextBox control from the normal vertical line to an underscore?
2
by: PA | last post by:
Hi, I want to implement the following in an applet: ^ | | + + + + + +H | + | + | H | +
0
by: minjie | last post by:
Hello, I have several reports that were written with ADO shape command (in C++) to access Microsoft Access database. Now we have migrated all the data from Access to DB2 UDB (version 8.1), and the...
1
by: AJ | last post by:
Hi guys, any clues or suggesstion on how to programatically change the shape of a button from rectangular to say elliptical or circular. Meaning that when the mouse hovers just within the shape,...
8
by: Boni | last post by:
Dear all, imagine this is scroll bar. Min|-------------|scroller|---------|Max The position of scroller is set with Value. How do I change the width of scroller? Thank you in advance, Boni
2
by: moondaddy | last post by:
I'm trying to do something real simple. Add a thumb to a grid at the end of a line using c#. the code executes but I dont see the thumb. Can anyone explain what and what I need to do to properly...
2
by: mjrtom19 | last post by:
I have a Jframe using a menubar to determine the color and shape of a graphics2d object, at the moment the color stays red no matter what. I think the problem is in the itemListener in the inner...
1
by: pankajprakash | last post by:
Hi, I have a word file which contains numbers of shapes. Each shape contain some textboxes. I am copying that file to another location and assigning some values to those textboxes of those shapes....
0
by: Bajwa | last post by:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.