kartal
kartal

Reputation: 18086

how to initialize new textbox in specific position in wpf

I am using InkCanvas control and I want to add a textbox in it as a child in specific position I succeeded to add it but not in the correct position ? how I can transform it or any another method ?

Upvotes: 3

Views: 5843

Answers (2)

Ed Swangren
Ed Swangren

Reputation: 124652

You can use the attached properties Left and Top like so:

var myTextBox = new TextBox();
myCanvas.Children.Add( myTextBox );
InkCanvas.SetLeft( myTextBox, someLeftValue );
InkCanvas.SetTop( myTextBox, someTopValue );

Upvotes: 4

Dan J
Dan J

Reputation: 16708

The InkCanvas isn't a panel type (note it inherits from FrameworkElement), but it does contain attached properties (as Ed S. mentioned) that let you position children as though it were a Canvas panel:

<InkCanvas>
  <TextBox InkCanvas.Top="50" InkCanvas.Left="50"/>
</InkCanvas>

Alternatively, you can also insert a panel as the child of the InkCanvas. For example:

<InkCanvas>
  <Canvas>
    <TextBox Canvas.Top="50" Canvas.Left="50"/>
  </Canvas>
</InkCanvas>

Upvotes: 1

Related Questions