473,797 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Apply a control template to a thumb with c#

I have a wpf app and need to apply a control template to a thumb at runtime,
but I can't do it the same way I would apply a style. this is what I want
to do:

Thumb thm = new Thumb();
thm.Template = TryFindResource ("myThumbTempla te") as Template;

but of course, this doesn't work.

Any advise?

Thanks.

--
mo*******@newsg roup.nospam
Jun 27 '08 #1
3 1417
Hi George,

I performed a test based on your description but didn't reproduce the
problem on my side. I could set the Template property of a Thumb control at
run time.

The following is XAML:

<Window x:Class="WpfApp lication1.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300" Loaded="Window_ Loaded" >
<Window.Resourc es>
<ControlTemplat e x:Key="ThumbTem plate" TargetType="{x: Type Thumb}">
<Ellipse Width="20" Height="20" Fill="Blue"/>
</ControlTemplate >
</Window.Resource s>
<StackPanel>
<Canvas Name="myCanvasS tretch" Width="200" Height="200"
Background="Pin k">
<Thumb Name="myThumb" Canvas.Left="80 " Canvas.Top="80"
Background="Blu e"
Width="20" Height="20" />
</Canvas>
</StackPanel>
</Window>

The code in the Window1.cs file:

public partial class Window1 : Window
{
public Window1()
{
InitializeCompo nent();
}

private void Window_Loaded(o bject sender, RoutedEventArgs e)
{
this.myThumb.Te mplate = TryFindResource ("ThumbTemplate ") as
ControlTemplate ;
}
}

Build and run the application. The Thumb control is rendered as a blue
ellipse.

Is there any difference between your code and mine?

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #2
Thanks Linda,

you gave the answer I was looking for:

= TryFindResource ("ThumbTemplate ") as ControlTemplate ;

I wasnt using as "ControlTemplat e" which is why it failed.

"Linda Liu[MSFT]" <v-****@online.mic rosoft.comwrote in message
news:Md******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi George,

I performed a test based on your description but didn't reproduce the
problem on my side. I could set the Template property of a Thumb control
at
run time.

The following is XAML:

<Window x:Class="WpfApp lication1.Windo w1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300" Loaded="Window_ Loaded" >
<Window.Resourc es>
<ControlTemplat e x:Key="ThumbTem plate" TargetType="{x: Type Thumb}">
<Ellipse Width="20" Height="20" Fill="Blue"/>
</ControlTemplate >
</Window.Resource s>
<StackPanel>
<Canvas Name="myCanvasS tretch" Width="200" Height="200"
Background="Pin k">
<Thumb Name="myThumb" Canvas.Left="80 " Canvas.Top="80"
Background="Blu e"
Width="20" Height="20" />
</Canvas>
</StackPanel>
</Window>

The code in the Window1.cs file:

public partial class Window1 : Window
{
public Window1()
{
InitializeCompo nent();
}

private void Window_Loaded(o bject sender, RoutedEventArgs e)
{
this.myThumb.Te mplate = TryFindResource ("ThumbTemplate ") as
ControlTemplate ;
}
}

Build and run the application. The Thumb control is rendered as a blue
ellipse.

Is there any difference between your code and mine?

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.


Jun 27 '08 #3
Hi George,

Thank you for your confirmation! I'm glad to hear that the problem is
solved now.

If you have any other questions in the future, please don't hesitate to
contact us. It's always our pleasure to be of assistance!

Have a nice weekend!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #4

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

Similar topics

1
2815
by: Stefan Siegl | last post by:
Hello, I am trying to learn XSLT to use it in another project. I start reading the book "Java and XSLT" and tried the examples and they are went quite fine (how suprising *g*). Then I tried to adopt these examples to my files. Unfortunately I did not work even though the styleSheet is very simple. Perhaps you can help me with it.
1
2717
by: Daryl | last post by:
Hello I am using apply-templates and would like to pass a parameter to the template using with-param. Using call-template passes the parameter, but when I use apply-templates, the parameter seems to be lost. Can parameters be passed with apply-templates? Any ideas? <!--xml--> <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="tran2.xsl"?> <doc>
5
1870
by: david hepworth | last post by:
Hi All I will try to explain my problem. I am wishing to apply a template to the following XML. There are multiple event nodes within the register root node. For each of the event nodes there are a list of students taking the Event. I wish to apply a template (and thus get the data) for the same student across the events. I can apply the template to student 18 for event 1, how do i then get the data for student 18 from event 2 and...
2
1910
by: parksch2 | last post by:
Quick question: How would I nest the apply templates on the following XML structure? /ITEM/CHILD/ITEM/CHILD/ITEM/CHILD I would first like to apply templates on /ITEM/CHILD. Within that template, I would like to apply a template on ITEM/CHILD (the children of the first ITEM/CHILD). Then within the second level template, I would again like to apply a template on its children (the grandchildren
3
1660
by: bjam | last post by:
Help! The apply-templates function is not currently allowing me to select a specific template... eventhough I tried putting a select statement, it does not seem to work??? Can someone help show how I can select the first template and then have it select others? Below is a sample of the xml as well as the .xsl file when I do something like the following in the main section it does not seem to work, it only works when I remove the select...
6
4009
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual as well. To support thin-template, I need to make virtual function as inline. Now, I know that compiler would generate an out-of-line copy when it
2
1659
by: jimbo_vr5 | last post by:
Hey I think i've figured out the idea behind apply-templates. But going through the tutorial on <http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply just something that i dont get! In the following i've copy pasted the example from <http://www.w3schools.com/xsl/xsl_apply_templates.asp> into this post. I divide into sections and my real question will come after the code snippet:
0
1908
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers... then taking that date range and finding dates specifiec between them (in a list of dates) and putting snap marks, so if you slide it near one of them it should snap to that tick, but that part i cant figure out. the rest seems ok so far... here...
3
2792
by: abhishek.smu | last post by:
Given an XML like: <root> <node>8</node> <node>21</node> <node>-7</node> <node>13</node> <node>43</node> <node>2</node> </root>
0
9685
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, 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...
0
10469
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, 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...
0
10246
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 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...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
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...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.