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. -
cornerThumb = new Thumb();
-
// Set some arbitrary visual characteristics.
-
cornerThumb.Cursor = customizedCursor;
-
cornerThumb.Height = cornerThumb.Width = 10;
-
cornerThumb.Opacity = 0.40;
-
cornerThumb.Background = new SolidColorBrush(Colors.MediumBlue);
Thanks for any input.
--
6 21823
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: - <Thumb Height="10" Width="10" Opacity=".4" Background="MediumBlue">
-
<Thumb.Style>
-
<Style TargetType={x:Type Thumb}>
-
<Style.Setters>
-
<Setter Property="Template">
-
<Setter.Value>
-
<ControlTemplate TargetType="{x:Type Thumb}">
-
<Ellipse.../>
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style.Setters>
-
</Style>
-
</Thumb.Style>
-
<Thumb.Cursor>
-
</Thumb.Cursor>
-
</Thumb>
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"[quote]
-
-
<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.
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: -
<ResourceDictionary
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-
-
>
-
-
-
<Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="Thumb"
-
x:Key="TestRoundThumb" <Setter Property="Template">
-
<Setter.Value>
-
<ControlTemplate TargetType="{x:Type Thumb}">
-
<Ellipse Width="20" Height="15" Stroke="Blue"
-
StrokeThickness="2"></Ellipse>
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style>
-
</ResourceDictionary>
and here's the code in the button click event: -
private void RoundThumb(object sender, RoutedEventArgs e)
-
{
-
Thumb roundThumb = new Thumb();
-
roundThumb.Height = 15;
-
roundThumb.Width = 20;
-
roundThumb.Style = (Style)(this.Resources["TestRoundThumb"]);
-
myGrid.Children.Add(roundThumb);
-
}
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:KZ******** ********@TK2MSF TNGHUB02.phx.gb l...
Thanks Keith. I hope you don't mind that I revised your code a little as
follows:
<Window x:Class="Window sApplication1.W indow1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Title="WindowsA pplication1" Height="300" Width="300"
>
<Thumb Height="10" Width="10" Opacity=".4" Background="Med iumBlue">
<Thumb.Style>
<Style TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e 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.
As you may already have known, you could still define the style (template)
in XAML. Then you could use FindResource (method of FrameworkElemen t) 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="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e 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="Med iumBlue">
</Thumb>
</Grid>
Code:
thumb1.Style = (Style) grid1.FindResou rce("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.
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.Resourc es>
<ResourceDictio nary Source="Diction ary1.xaml" />
</Window.Resource s>
Here's the style in Dictionary1.xam l:
<Style x:Key="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e TargetType="{x: Type Thumb}">
<Ellipse Width="15" Height="15" Stroke="DarkSla teGray"
StrokeThickness ="0.5">
<Ellipse.Fill >
<SolidColorBrus h Color="DarkBlue " Opacity="0.2"></SolidColorBrush >
</Ellipse.Fill>
<Ellipse.Bitmap Effect>
<DropShadowBitm apEffect Color="Black" Direction="320"
ShadowDepth="5" Softness="0.5" Opacity="0.2" />
</Ellipse.BitmapE ffect>
</Ellipse>
</ControlTemplate >
</Setter.Value>
</Setter>
</Style>
and here's the c# that used it:
Thumb tb = new Thumb();
Canvas.SetLeft( tb, 100);
Canvas.SetTop(t b, 100);
myCanvas.Childr en.Add(tb);
tb.Style = (Style)this.Fin dResource("Thum bStyle");
"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:a4******** ********@TK2MSF TNGHUB02.phx.gb l...
As you may already have known, you could still define the style (template)
in XAML. Then you could use FindResource (method of FrameworkElemen t) 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="ThumbSty le" TargetType="{x: Type Thumb}">
<Setter Property="Templ ate">
<Setter.Value >
<ControlTemplat e 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="Med iumBlue">
</Thumb>
</Grid>
Code:
thumb1.Style = (Style) grid1.FindResou rce("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.
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
InvalidOperatio nException.
Therefore you could simply put resources in App.xaml within
<Application.Re sourcesand those resources will be shared by all your code
in the same assembly.
For ResourceDiction ary defined in separate .xaml files, you could use
following code to load it:
ResourceDiction ary rd = new ResourceDiction ary();
rd.Source = new Uri(@"Dictionar y1.xaml", UriKind.Relativ e);
Then you can use rd["resource_k ey"] 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
by: PA |
last post by:
Hi,
I want to implement the following in an applet:
^
|
| + + + + + +H
| +
| +
| H
| +
|
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 shape command does
not work any more. I have changed the provider and connection string
from:
pConn->Provider = "MSDataShape";
SAFE_CALL( pConn->Open( "DBQ=myAccessDB.mdb; DefaultDir=.;
Driver={Microsoft Access Driver (*.mdb)};", "sa", "", 0...
|
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, only then the Click event
can be generated.
Would be Great if you guys can help
Code can be either in C# or VB.Net
Thanx
AJ
|
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
| |
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 show the thumb?
Here's the xaml for the window and the c# below.
<Window x:Class="DragLineSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
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 class myShape, but I dont know what it is.
Heres the code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics2D.*;
import java.awt.geom.*;
|
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. Now I have to assign the values to those textboxes then I have to ungroup those shape first then only I can assign values those text boxes. Now the problem is that when I ungroup those shapes, they change their locations in the document. I do not...
|
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;
public class MyPolygonButton
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |