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 succeed开发者_如何转开发ed to add it but not in the correct position ? how I can transform it or any another method ?
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 );
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>
精彩评论