Silverlight - add tooltip to a rotated textblock - silverlight

I have a TextBlock which is rotated at 90 degrees in the Silverlight XAML:
<TextBlock Name="txbPW" Text="West">
<TextBlock.RenderTransform>
<RotateTransformAngle="90" />
</TextBlock.RenderTransform>
</TextBlock>
I want to add a tooltip (not rotated) to it. Any help?

What's your problem? Do you want to show the tooltip rotated too?? Or don't?? Or are you just asking to add a tooltip to a textblock???
If you only want to add a tooltip to a textblock you have to do something like this:
<TextBlock Name="txbPW" Text="West">
<TextBlock.RenderTransform>
<RotateTransformAngle="90" />
</TextBlock.RenderTransform>
<ToolTipService.ToolTip>
<ToolTip Content="ToolTip"></ToolTip>
</ToolTipService.ToolTip>
</TextBlock>
http://bouncetadiss.blogspot.com.es/2010/02/tooltip-for-textblock-in-silverlight.html

Related

WPF: Textblock as item in ComboBox: how to center the text of Textblock vertically?

I use WPF 4.5, Caliburn Micro 2, VS2013. I use TextBlock as item in ComboBox.
The height of ComboBox is 80.
The height of TextBlock is 50.
The font size of text inside the TextBlock is standard.
My following sample xaml code works but it shows the text not vertically centered in TextBlock. How to make the text vertically centered with/without changing the height of TextBlock to Auto? Thank you in advance.
<ComboBox Width="150"
Height="80"
VerticalContentAlignment="Center"
ItemsSource="{Binding Path=Locations}"
SelectedIndex="0"
SelectedItem="{Binding Path=SelectedLocation,
Mode=OneWayToSource}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Aquamarine"
Text="{Binding Path=Address}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
And here is the screenshot:
A TextBlock should not have a height but its container should instead. If you want to set the background color for your TextBlock then wrap your TextBlock in a Border or a Grid and set the height on them instead.
Like
<Grid Height="50>
<TextBlock VerticalAlignment="Center" Text....../>
</Grid>
Text-Align="center"
or you could use a margin on each of the sides.

Add image into a tooltip

I have some TextBlocks with tooltips and I'd like to add an image into the tooltips (that means, I'd like to have tooltips with text and images).
Does anybody knows how could I do that in a simple way?
Thanks a lot!
This is one way to approach it:
<TextBlock>
<TextBlock.ToolTip>
<StackPanel Orientation="Horizontal">
<Image Source="images/Item 2.gif" />
<TextBlock>My tooltip text</TextBlock>
</StackPanel>
</TextBlock.ToolTip>
Here is my text.
</TextBlock>
Instead of
<TextBlock ToolTip="Content"/>
You can do:
<TextBlock>
<TextBlock.ToolTip>
<!--insert everything you want here-->
<TextBlock Text="Content"/>
</TextBlock.ToolTip>
</TextBlock>

Flip a UIElement but preserve text inside from flipping

I think the title is pretty straightforward. I'm using some custom controls. I want to flip the tab header of a custom tab control. I tried a layout transform (ScaleTransform X = -1) to flip horizontally the tab header. But obviously I want the text inside not to be mirrored. I can't find a way so far.
You can do this by giving the TabItem a HeaderTemplate, and applying a ScaleTransform there also:
<TabControl>
<TabItem Header="Hello, World!">
<TabItem.LayoutTransform>
<ScaleTransform ScaleX="-1" />
</TabItem.LayoutTransform>
<TabItem.HeaderTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding}">
<ContentPresenter.LayoutTransform>
<ScaleTransform ScaleX="-1" />
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</DataTemplate>
</TabItem.HeaderTemplate>
</TabItem>
</TabControl>

Text stretch in WPF TextBlock

I want to stretch the text in WPF Textblock with out changing the font size of the textblock?
use a layout or render transform to scale your text in the X or Y direction depending on what you want
LayoutTransform causes the scale to be applied prior to the layout pass which means the element is rendered with the scaled size taken in to account. Whereas the RenderTransform applies the scaling after the layout pass so the element is spaced at normal size then the scale is applied.
Something like
<TextBlock Text="Foo">
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</TextBlock.RenderTransform>
</TextBlock>
To stretch text over the entire control and make it narrower, I use ViewBox and Layout Transform:
<DockPanel>
<Viewbox>
<Viewbox.LayoutTransform>
<ScaleTransform CenterX="50" ScaleX="0.5" />
</Viewbox.LayoutTransform>
<TextBlock Text="Some random text." HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Viewbox>
</DockPanel>

How to add a border to the Text inside a TextBlock in WPF?

I am kinda new to WPF, dont know if the question is weird. I wanted to know if its possible to add a border around the text inside a textBlock.
EDIT:
As per suggestion I have tried both but without much success:
<Border BorderBrush="#FF0B232F" BorderThickness="2">
<TextBlock HorizontalAlignment="Left" Text="TextBlock" TextWrapping="Wrap" FontSize="36" FontWeight="Bold" Foreground="#FF88BCCD" OpacityMask="Black"/>
</Border>
and
<Label BorderBrush="#FF0B232F" BorderThickness="2,2,2,2" Content="TextBlock" FontSize="36" FontWeight="Bold" Foreground="#FF88BCCD" />
Am I doing something wrong here?
In such cases I use Label or TextBlock placed in Border.
Both your approaches are correct, however, if you have the textblock/label inside a grid (or any other container) declared as you have, its contents will stretch.
Try setting the VerticalAlignment and/or HorizontalAlignment to an appropriate setting (Top/Left, Center)..
something like this:
<Border BorderBrush="#FF0B232F" BorderThickness="2" VerticalAlignment="Top">
<TextBlock HorizontalAlignment="Left" Text="TextBlock" TextWrapping="Wrap" FontSize="36" FontWeight="Bold" Foreground="#FF88BCCD" OpacityMask="Black"/>
</Border>
Assuming that you are asking for a full size TextBlock with a border overlay within the bounds of the TextBlock you could wrap it in a Grid and draw the borders over the top of the TextBlock like this...
<Grid HorizontalAlignment="Left">
<TextBlock Text="TextBlock" TextWrapping="Wrap" FontSize="36" FontWeight="Bold" Foreground="#FF88BCCD" OpacityMask="Black" />
<Border BorderBrush="#FF0B232F" BorderThickness="2" />
</Grid>
Because we haven't specified the grid row and column on the TextBlock and Border objects the border overlays on top of the TextBlock.
if you just want to have a border around your textblock or any other control use :
<Border>
<TextBlock></TextBlock>
</Border>
you set border properties like color ,cornerradius ,thickness,...

Resources