Add image into a tooltip - wpf

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>

Related

Showing download percentage with xaml

I am trying to figure out a way to show the user the download progress like this:
17.38/50Mb's
But I need to bidnd through xaml with StringFormat
To use StringFormat in XAML,
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding DownloadSizeInMB, StringFormat={0:0.00}}" />
<TextBlock Text="/" />
<TextBlock Text="{Binding TotalSizeInMB, StringFormat={0:0.00}}" />
<TextBlock Text="Mb's" />
</StackPanel>
But these comes with some Margin between the TextBlocks.
I would suggest you use MultiBinding instead.

Silverlight for Windows phone 7 - two text blocks after each other with NO linebreak

I'm relatively new to Windows Phone 7 development, so bear with me on this.
I've two text blocks, each with binding to two different properties, like this:
<TextBlock Text="{Binding ID}" />
<TextBlock Text="{Binding Title}"/>
So when I deploy this code, on the phone it will be something like this:
6
This is a title
I want the text to be displayed this way instead:
6: This is a title
What is the easiest way to achieve this?
<TextBlock>
<Run Text="{Binding ID}" />:
<Run Text="{Binding Title}"/>
</TextBlock>
Three most common UI layout elements are StackPanel, Grid & Canvas. Here's one way..
<StackPanel Orientation="Horizontal">
<TextBlock .. />
<TextBlock .. />
</StackPanel>

Specifying a Button Content that has mix of text and a Binding path

How do you specify the Content of a button that is a mix of some TEXT and a Binding path?
Like this:
<Button Content= "TEXT" + "{Binding Path=ButtonContent}"
For most cases you can use StringFormat in the Bindings, like for a TextBlock
<TextBlock Text="{Binding ElementName=textBox,
Path=Text,
StringFormat='{}{0} - Added Text'}"/>
However, this has no effect on a ContentControl (which Button inherits from). Instead, you can use ContentStringFormat
<Button Content="{Binding ElementName=textBox,
Path=Text}"
ContentStringFormat="{}{0} - Added Text"/>
Also, for
ContentControl you use ContentStringFormat
HeaderedContentControl you use HeaderStringFormat
ItemsControl you use ItemStringFormat
Something like this:
<Button>
<Button.Content>
<TextBlock Text="{Binding SomeBindingPath, StringFormat='Some text {0}'}"/>
</Button.Content>
</Button>
OR
<Button>
<Button.Content>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Some Text"/>
<TextBlock Text="{Binding SomeBindingPath}"/>
</StackPanel>
</Button.Content>
</Button>
Basically, you can put any content inside a button using the approach above.
Building on the other answers, this is a little more terse:
<Button Content="{Binding FirstName, StringFormat='Click here, {0}!'}" />

How to bind property of parent element

i have a quick Binding Question about Silverlight.
I have some Expander and want to overwrite their Header Templates
<Controls:Expander Header="MyHeaderTitle"
HeaderTemplate="{StaticResource MyExpanderHeaderTemplate}">
//Content
</Controls:Expander>
<Controls:Expander Header="MyNextHeaderTitle"
HeaderTemplate="{StaticResource MyExpanderHeaderTemplate}">
//Content
</Controls:Expander>
In the header template i have an textbox and want to bind the text to the Header of the expander.
<DataTemplate x:Key="MyExpanderHeaderTemplate">
<TextBlock Text="{Binding Path=Header}">
// some triggering stuff
</TextBlock>
</DataTemplate>
I tried some stuff with RelativeSource (Self and TemplatedParent) but nothing seems to work.
Some Ideas would be great, thx.
Take a look at RelativeSourceMode.FindAncestor
<TextBlock
Text="{Binding RelativeSource={RelativeSource RelativeSourceMode=FindAncestor, AncestorType={x:Type Controls:Expander}}}, Path=Header"/>
Just do this
<DataTemplate x:Key="MyExpanderHeaderTemplate">
<TextBlock Text="{Binding}"/>
</DataTemplate>
Thanks for the quick answers.
FindAncestor doesn't seem to work under Silverlight the Way it does in WPF (can't resolve AncestorType..)
But {Binding} or {Binding .} do the trick!
have you tried:
<DataTemplate x:Key="MyExpanderHeaderTemplate">
<TextBlock Text="{Binding .}">
// some triggering stuff
</TextBlock>
</DataTemplate>

Set superscript and subscript in formatted text in wpf

How can I set some text as subscript/superscript in FormattedText in WPF?
You use Typography.Variants:
<TextBlock>
<Run>Normal Text</Run>
<Run Typography.Variants="Superscript">Superscript Text</Run>
<Run Typography.Variants="Subscript">Subscript Text</Run>
</TextBlock>
You can use something like <TextBlock>5x<Run BaselineAlignment="Superscript">4</Run> + 4</TextBlock>.
However, as far as I know, you will have to reduce the font-size yourself.
It's interesting to note that for some characters (m2, m3, etc) a superscript is not needed, but the unicode character can be used. For example:
<Run Text=" m³" />
This would show m3.
I used a layout transform, because Typography.Variants often doesn't work:
<TextBlock Text="MyAmazingProduct"/>
<TextBlock Text="TM">
<TextBlock.LayoutTransform>
<!-- Typography.Variants="Superscript" didn't work -->
<TransformGroup>
<ScaleTransform ScaleX=".75" ScaleY=".75"/>
<TranslateTransform Y="-5"/>
</TransformGroup>
</TextBlock.LayoutTransform>
</TextBlock>
<TextBlock Text="{Binding Path=Version, StringFormat={} v{0}}"/>
The advantage of using a LayoutTransform is that it is insensitive to the fontsize. If the fontsize is changed afterwards, this superscript works where explicit FontSize setting breaks.
I don't know if you need this to work with FormattedText specifically, or you mean derivations of Inline, but the following will work on Inlines, even if Typography.Variants="Superscript" fails to work.
TextRange selection = new TextRange(document.ContentStart, document.ContentEnd);
selection.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Superscript);
Hope it helps!
Typography.Variants works only for open type fonts. If you dont like your superscripts/subscripts going outside the height of actual text then you can use something like the following:
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="10" Margin="0,5,0,0">1</TextBlock>
<TextBlock FontSize="30">H</TextBlock>
<TextBlock FontSize="10" Margin="0,20,0,0">2</TextBlock>
</StackPanel>
This is the only thing that worked for me. It also gives you more control over the alignment and font size.
<TextBlock Grid.Row="17">
3 x 3<Run FontSize="6pt" BaselineAlignment="TextTop">2</Run>)
</TextBlock>
Setting for superscript works fine with the following code:
<TextBlock Text="(cm" />
<TextBlock ><Span BaselineAlignment="Top" FontSize="8">2</Span></TextBlock>
<TextBlock Text=")" />
Setting the Baseallignment for subscript in the Span tag did not work for me.
I tried the following code and it worked fine.
<TextBlock Text="H" />
<TextBlock Text="2" Margin="-2,0,-2,0" TextBlock.LineHeight="3" >
<TextBlock Text="O" />

Resources