473,734 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble programmaticall y adding thumb to grid in WPF window.

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="DragLi neSample.Window 1"
xmlns="http://schemas.microso ft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
Title="DragLine Sample" Height="300" Width="300"
>
<Grid Name="myGrid">
<Button Canvas.Right="0 " Canvas.Bottom=" 0" Width="50" Height="20"
Name="myBtn">Hi t Me</Button>
</Grid>
</Window>

void DrawLineWithThu mb()
{
visualChildren = new VisualCollectio n(myGrid);

Line myLine;
myLine = new Line();

myLine.Stroke = Brushes.Black;
myLine.StrokeTh ickness = 3;
this.myGrid.Chi ldren.Add(myLin e);
myLine.X1 = 30;
myLine.Y1 = 20;
myLine.X2 = 70;
myLine.Y2 = 40;

cornerThumb = new Thumb();
cornerThumb.Cur sor = Cursors.SizeNWS E;
cornerThumb.Hei ght = cornerThumb.Wid th = 10;
cornerThumb.Opa city = 0.40;
cornerThumb.Bac kground = new SolidColorBrush (Colors.MediumB lue);
cornerThumb.Arr ange(new Rect(myLine.X1 - 5, myLine.Y1 - 5,
cornerThumb.Wid th, cornerThumb.Hei ght));

visualChildren. Add(cornerThumb );
}


--
mo*******@noema il.noemail
Jan 9 '07 #1
2 4710
Hi moondaddy,

The Thumb object doesn't get shown because you have added it in the wrong
collection. In the code you have provided, you're adding it to
visualChildren. However, visualChildren is the parent of myGrid. In this
case, you have to add the Thumb to myGrid.

Also, in the grid, we don't use Arrange to change the position of a
control. We have to use Margin property. Here, I worked out a sample that
works fine on my machine. Hope that helps.

VisualCollectio n visualChildren = new VisualCollectio n(myGrid);

Line myLine;
myLine = new Line();

myLine.Stroke = Brushes.Black;
myLine.StrokeTh ickness = 3;
this.myGrid.Chi ldren.Add(myLin e);
myLine.X1 = 30;
myLine.Y1 = 20;
myLine.X2 = 70;
myLine.Y2 = 40;

Thumb cornerThumb = new Thumb();
cornerThumb.Cur sor = Cursors.SizeNWS E;
cornerThumb.Hei ght = cornerThumb.Wid th = 10;
cornerThumb.Opa city = 0.40;
cornerThumb.Bac kground = new SolidColorBrush (Colors.MediumB lue);
cornerThumb.Hor izontalAlignmen t = HorizontalAlign ment.Left;
cornerThumb.Ver ticalAlignment = VerticalAlignme nt.Top;
cornerThumb.Mar gin = new Thickness(myLin e.X1 - 5, myLine.Y1 -
5, myLine.X1 - 5 + cornerThumb.Wid th, myLine.Y1 - 5 + cornerThumb.Hei ght);

this.myGrid.Chi ldren.Add(corne rThumb);

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
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.)

Jan 10 '07 #2
Thanks that worked. I tried adding it to the grid earlier, but it didn't
show because I wasn't setting the position correctly by using the grid's
margin property. This did the trick.
"Kevin Yu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:l4******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi moondaddy,

The Thumb object doesn't get shown because you have added it in the wrong
collection. In the code you have provided, you're adding it to
visualChildren. However, visualChildren is the parent of myGrid. In this
case, you have to add the Thumb to myGrid.

Also, in the grid, we don't use Arrange to change the position of a
control. We have to use Margin property. Here, I worked out a sample that
works fine on my machine. Hope that helps.

VisualCollectio n visualChildren = new VisualCollectio n(myGrid);

Line myLine;
myLine = new Line();

myLine.Stroke = Brushes.Black;
myLine.StrokeTh ickness = 3;
this.myGrid.Chi ldren.Add(myLin e);
myLine.X1 = 30;
myLine.Y1 = 20;
myLine.X2 = 70;
myLine.Y2 = 40;

Thumb cornerThumb = new Thumb();
cornerThumb.Cur sor = Cursors.SizeNWS E;
cornerThumb.Hei ght = cornerThumb.Wid th = 10;
cornerThumb.Opa city = 0.40;
cornerThumb.Bac kground = new
SolidColorBrush (Colors.MediumB lue);
cornerThumb.Hor izontalAlignmen t = HorizontalAlign ment.Left;
cornerThumb.Ver ticalAlignment = VerticalAlignme nt.Top;
cornerThumb.Mar gin = new Thickness(myLin e.X1 - 5, myLine.Y1 -
5, myLine.X1 - 5 + cornerThumb.Wid th, myLine.Y1 - 5 + cornerThumb.Hei ght);

this.myGrid.Chi ldren.Add(corne rThumb);

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

=============== =============== =============== =====
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.)

Jan 10 '07 #3

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

Similar topics

1
2586
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i access the recordset it displays the results, what the real issue is that the entry is not made into the database even though i use the Update command and i have also tried the BeginTrans and CommitTrans nothign seems to work and i am unable to...
2
4546
by: Jozef | last post by:
Hello, I am trying to put together a module and open a workspace on a database that has a simple password (using Access XP). This is the lin that I'm having trouble with; Set wrk = CreateWorkspace("TestWrkspc", "Admin", conDbPwd) conDBPwd is a variable that contains the password. There is no independant workgroup file, just the default. This is the error message I'm getting;
0
1538
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server has deleted the process. It's a fresh Windows 2000 server install, but I also installed the ASP.net
2
15070
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
2
2021
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my office computer (under Linux), but I have to write some code for the system simulator for the Cell BE processor (the thing inside the PS3), which is apparently a PPC architecture, and I can't get the clock function to
6
10121
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
5
3740
by: Nathan Sokalski | last post by:
I have css that would normally be placed in style tags in the header of the Master page that I want to add programmatically for a specific Web Content Form (the *.aspx page). How do I do this for a Web Content Form? I cannot use style tags in a Web Content Form, and I am having trouble figuring out how to add all the desired css properties to a System.Web.UI.WebControls.Style object. Can anyone help me? Thanks. -- Nathan Sokalski...
3
1498
by: jaesik | last post by:
Hi all, I've been working on my personal portfolio website and been struggling a lot because of J-query. Since my j-query level is not like master.. I usually modify existing j-query plugins to meet my needs and this time I'm trying to combine both accordion plugin and slideshow plugin. I used the tutorial for accordion from this website - http://acrisdesign.com/2010/03/jquery-tutorial-toggle-effect-on-hoverclick also used the...
1
1484
by: Connor Bergman | last post by:
Im trying to create a bank statement basically, and Im having trouble formatting the output to a grid, from a .txt file. And I wrote the file, and can read the first line, and want to pull the date out, and seperate the amount. And with the following lines say the date, type of transaction, the location, amount of the transaction, and finally the running total. here is what I'm looking to achieve with this:(with all the numbers and columns...
0
8946
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
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
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
9310
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
9236
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
8186
agi2029
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...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.