Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi!

I'm working on a WPF program in C#. I'm still a bit new to WPF.

I wanted to know how to set a control's position(image for instance)- from code. There isn't a "img.left" in WPF. I don't know how to control an image's position by code. Can someone please help me?

Thanks!

Posted

No absolute positioning in WPF

 

There is no absolute positioning in WPF. Instead, controls are automatically placed and sized according to their margins, the margins of adjacent controls, and the padding of their container. The system is very similar to that used in web pages.

 

Good luck :cool:

Never trouble another for what you can do for yourself.
Posted

Re: No absolute positioning in WPF

 

There is no absolute positioning in WPF. Instead, controls are automatically placed and sized according to their margins, the margins of adjacent controls, and the padding of their container. The system is very similar to that used in web pages.

 

Good luck :cool:

 

I'm still new to WPF- can you please help me? How do I do this: I want an image to be at a certain point on the screen- which it is already. Then- at a timer tick- I want the image to move to a different location. Maybe you could please explain a bit more about the WPF positioning?

Thanks!

Posted
Look into the SetLeft and SetTop methods. I don't know if they are best practice or not, but they should help you out.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Administrators
Posted

It really depends on exactly what you want to do as which method may be best, are you using the timer to drive some animation or is it being used for some other reason?

 

SetLeft and SetTop (methods of the Canvas object) will certainly give you control over the position of a visible element however if you are looking at just doing animation then WPF has a pretty sophisticated system built in that may better suit your needs.

 

Out of curiosity could you give a bit more detail about what you are trying to do?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
It really depends on exactly what you want to do as which method may be best, are you using the timer to drive some animation or is it being used for some other reason?

 

SetLeft and SetTop (methods of the Canvas object) will certainly give you control over the position of a visible element however if you are looking at just doing animation then WPF has a pretty sophisticated system built in that may better suit your needs.

 

Out of curiosity could you give a bit more detail about what you are trying to do?

 

Hi!

The timer doesn't drive an animation. The timer just changes an image into a certain picture. It's basically a program for teaching something to kids.

Posted
Could you not just simply load the image into the control at runtime rather than changing it's position?

 

No. There's an audio file, and when the speaker says something- a different image appears. At one point- I want tthe image to be at a different position.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...