How do I move the text in a silverlight textbox - silverlight

I make a silverlight TextBox. The Text is vertically centered in the box so that I am required to make the textbox a certain size in order to see the text.
Can I make the text appear at the top of the box so that I am not required to have such large textboxes?

If you want to put the text at the top of the textbox then instead of VerticalAlignment="Center" use VerticalAlignment="Top"
If you feel that the text is not filling the textbox then try using a negative number for the padding property in your xaml e.g. Padding="-3"

Related

Image to not cause a row size change

I have a simple Grid with three columns. In one of these rows, I have (in column order): A TextBlock, a TextBox, and a Button. The Button contains an Image for it's content.
My issue is that the Image always sizes to display it's full content which enlarges the button. I don't care what size the image's source is; I want the Button to be the same size as the row already is due to the TextBlock and the TextBox. I don't want to specify a hard coded value for the image size. That's not the point. If a user's theme and/or font changes, the Grid row should still work as expected and the Button should always be the correct size.
I've tried a ViewBox, all sorts of alignment properties and bindings. No luck. Any ideas anyone?
<TextBlock VerticalAlignment="Center" Margin="4,0" x:Uid="RONumber" />
<TextBox x:Name="tbRO" InputScope="Number" MaxLength="8" Grid.Column="1" Margin="4" />
<Button x:Name="btnSearch" Click="Search_Click" Grid.Column="2">
<Image Source="Long Source Removed For Readability" />
</Button>
In the image below you can see the TextBox and to the right the Button with the Image inside it. Right below it is another TextBox which is correctly sized. And if I remove the button the top TextBox sizes the same.
Ok, so here's the answer. Because the elements are in the same row the XAML is not working. The binding I had made (before I even posted this question) to the ActualHeight always was 0. I instead bound the MaxHeight of the button to the ActualHeight of a random TextBox on another area of the screen. This worked.

Is there any difference between WPF TextBlock and TextBox?

What criteria must I consider when selecting one of these two controls?
Common to both TextBlocks and TextBoxes:
Can be used to display text
Can be set to specific Height and Width or be set to Auto so that they grow in size with the text.
Can set font size, font type, font styling, to wrap and to range left, right or centred.
Can have opacity set and have Pixel Shaders applied.
TextBlock:
Used for displaying text more focused typographically.
Can contain text set to different colors, fonts and sizes.
The line height can also be increased from the default setting to give more space between each line of text.
Text inside a TextBlock cannot be made selectable by the user.
TextBox:
Used for displaying text more focused for content input or when content is needed to be made selectable by the user.
Can only be set to one colour, one font size, one font type etc.
Have fixed Line Spacing.
Can also be set to a fixed height and width but also have scrollbars switched on to allow content to expand.
TextBlock is more lightweight control for displaying text and TextBox is used when you require user input or edit existing text. Proof for mem usage.

How do I make a TextBox that can grow wider than its parent?

Is there any way I can make a WPF TextBox dynamically grow beyond the bounds of its parent?
For example, I am allowing a user to type in an XPath string that could be very long (wide), I would like one of two possible things to happen:
The textbox could grow wider when the user types a certain amount of characters.
or
When the user initially clicks on the textbox, it kind of 'pops-out' and is very wide, wider than its container.
Is this possible?
You can set a negative Margin to allow it to grow wider than its parent.
<Grid>
<Grid Margin="50">
<TextBlock Margin="0,0,-50,0" Text="This is a very long text." />
</Grid>
</Grid>
You can try the following:
Put both the ParentControl and the TextBox inside a Canvas.
Locate the TextBox using fixed or dynamic coordinates relative to the ParentControl.
Set the TextBox Z-Index to higher value of the ParentControl.
Relocate and/or expend the TextBox based on TextBox events.

Can I limit WPF TextBlock height to two lines?

I just received a requirement to display a length of text in a control. The control is of a particular width and will be up to 2 lines in height. If it renders longer than two lines it will just display "..." at the end of the string.
Is this possible with any of the stock standard WPF controls?
Thanks,
D.
Set the Height of the TextBlock to be high enough to fit two lines. Set the TextWrapping to Wrap and the TextTrimming to CharacterEllipsis or WordEllipsis.
For the default Segoe UI 12Pt font, I find this does it
<TextBlock TextWrapping="Wrap" Height="40" TextTrimming="CharacterEllipsis" />
You could probably do some code behind to work out the height it should be be for a particular font if you want.
That's not standard behavior that I've ever found, but again I've not looked for it.
One possibility is to use a monospace font in a TextArea control, and then if the string is greater than however many characters fit in the area, only display the right N characters with the ellipses

Absolute positioning in WPF

I have a long text and show first sentence in a TextBlock.
I wish by clicking the TextBlock or a button to show a panel below the TextBlock with full text. I wish this panel be absolutely positioned and be displayed above any other elements, you can do a similar thing in HTML showing and hiding absolutely positioned 'div' element.
How to do this in WPF?
Thank you for any suggestions.
AdornerLayer can work, but may be a little complex. Other options include using PopUps or ToolTips -- you should look into those first as your easiest options.
If these all don't work, it'll really depends on what kind of panel you're using. For example, if you're using a Canvas, all you have to do is make sure to set the correct ZIndex on the element.
In order to make this more robust, I'd suggest the following:
<!-- Set Panel.ZIndex="99" when showing hidden area to ensure top placement -->
<Grid>
<TextBlock>This is my primary bit of text ...</TextBlock>
<!-- Canvas stays hidden until we want to show the rest of the text -->
<Canvas Visibility="Hidden">
<TextBlock Canvas.Bottom="-10">Content goes here</TextBlock>
</Canvas>
</Grid>
Put the long text in an AdornerLayer is the best option. Check out some links
http://msdn.microsoft.com/en-us/library/ms743737.aspx
http://wangmo.wordpress.com/2008/10/19/relations-between-adorner-adornerlayer-and-adornerdecorator/

Resources