WPF - Tooltip on a disabled hyperlink with an embedded TextBlock element - c#

I'm trying to put tooltips on disabled hyperlinks in my WPF app. The hyperlinks have embedded TextBlock elements for Text parameter binding. However, for some reason tooltips don't work on disabled hyperlinks with an embedded TextBlock element. Here is an example:
<Grid>
<StackPanel>
<TextBlock TextAlignment="Center" Margin="5">
<Hyperlink IsEnabled="False" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">Text</Hyperlink>
</TextBlock>
<TextBlock TextAlignment="Center" Margin="5">
<Hyperlink IsEnabled="True" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
<TextBlock Text="Text"/>
</Hyperlink>
</TextBlock>
<TextBlock TextAlignment="Center" Margin="5">
<Hyperlink IsEnabled="False" ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
<TextBlock Text="Text"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
This XAML describes three hyperlinks.
The first hyperlink is disabled, but has no embedded TextBlock element. The tooltip shows up fine.
The second hyperlink has an embedded TextBlock element, but is enabled. Again, the tooltip shows up fine.
The third hyperlink is disabled and has an embedded TextBlock element, which is what I need, but the tooltip is not shown.
What can I do to show tooltips on disabled hyperlinks with embedded TextBlock elements? I don't want to add the tooltip to the parent TextBlock, because I want the tooltip to only appear on the hyperlink text, and not the whole TextBlock area.
Thanks.

I know it sounds strange but this seems to work:
<TextBlock Text="Hello there" IsEnabled="False">
<Hyperlink ToolTip="ToolTip" ToolTipService.ShowOnDisabled="True">
<TextBlock Text="Text" />
</Hyperlink>
</TextBlock>
i.e., you have to disable the parent TextBlock.

Move Tooltip to textblock like this
<TextBlock TextAlignment="Center" Margin="5" ToolTip="ToolTip">
<Hyperlink IsEnabled="False" ToolTipService.ShowOnDisabled="True">
<TextBlock Text="Text"/>
</Hyperlink>
</TextBlock>

Related

Binding text with viewbox produces unwanted behaviour

The appeareance of my button is perfect if I define what the text is.
Working Image
<StackPanel Orientation="Horizontal">
<ContentControl ContentTemplate="{StaticResource Icons.Person}" Style="{StaticResource Icon}"/>
<TextBlock Text="PERSONS"/>
</StackPanel>
I want to set the text to be Binding to a variable but this Overlaps the image.
Appearance after Bindings
<StackPanel Orientation="Horizontal">
<ContentControl ContentTemplate="{StaticResource Icons.Person}" Style="{StaticResource Icon}"/>
<TextBlock Text="{Binding Persons"/>
</StackPanel>
Icon.xaml
<DataTemplate x:Key="Icons.Person">
<Viewbox>
<Path ......./>
</Viewbox>
</DataTemplate>
Path code is huge, if it's needed I'll upload it.
What I've tried is changing the Datatemplate to be only a ViewBox with a key, and change content control to be a stackpanel with a viewbox within it and the text box. Same effect would happen. May I ask how to fix this or what's an alternative to show my datatemplate/viewbox with a binding text field

TextBox seems to have a maxlength by default - Cant disable

When I try and push the source code from a site such as google into a textbox, the code is truncated after what appears to be a max length or height. I'm not quite sure which one it is yet.
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<CheckBox Margin="0,0,30,0" Content="Live Edit" IsChecked="{Binding isLiveEdit, Mode=TwoWay}"/>
<Button Width="130" Content="Run" Click="Run_Click"/>
<Button Content="Save Mods" IsEnabled="{Binding siteSaved}"/>
</StackPanel>
<ListBox Height="455" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<TextBox Text="{Binding source, Mode=TwoWay}" TextWrapping="Wrap" Width="600"/>
</ListBox>
</StackPanel>
It appears to not matter if I use TextBox or TextBlock. It hits this invisible limitation. The height of the control is still correct. For example I can keep scrolling but there is no text.
Here is a screenshot of where the textbox appears to end however the listbox that it is in will still allow me to continue to scroll as if it is populated with invisible data.

Text wrapping in pivot header

I am looking for a correct way to enable text wrapping in the header of Pivot control in my WP8 application.
Here is the code:
<phone:Pivot Title="MY APPLICATION">
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<phone:PivotItem Header="very long item name">
<Grid/>
</phone:PivotItem>
</phone:Pivot>
As you can see the 'TextWrapping' property is explicitly set to 'Wrap', but I do not observe any wrapping whatsoever. Does anyone know the workaround?
You need to set the Width of TextBlock explicitly for TextWrapping to work.
<TextBlock Text="{Binding}" TextWrapping="Wrap" MaxWidth="400" Height="Auto"/>
Above works fine.

Text longlistselector not completely visible

I have a little problem using the longlistselector (well more specifically the multilonglistselector) in windows phone 8.
I use binding to bind the name of an object to the items, the XAML code is as follow:
<Grid>
<TextBox x:Name="searchBox"
IsEnabled="{Binding IsConnected}"
HorizontalAlignment="Left" KeyUp="CheckKey"
Height="72" Margin="10,10,0,0" TextWrapping="Wrap" InputScope="Search" GotFocus="Select"/>
<toolkit:LongListMultiSelector EnforceIsSelectionEnabled="True" SelectionChanged="AdjustAddSelectionButton" x:Name="resultList" ItemsSource="{Binding Results}" HorizontalAlignment="Stretch" Height="434" Margin="10,87,0,0" VerticalAlignment="Top" >
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Title}" TextWrapping="Wrap">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DoubleTap="OpenArticleDetail" />
</toolkit:GestureService.GestureListener>
</TextBlock>
</Grid>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
</Grid>
The Binding takes place perfectly, but the text is sometimes too long and doesn't fit the screen. How would I go about wrapping this text to another line?, I 'll give a screenshot here
You didn't really state any specific problem or question you want answered. Please try to be a bit more clear in the future.
If you don't like that the TextBlock cuts off words that it can't fit, then you have several solutions.
TextBlocks have a TextWrapping property, so doing TextWrapping="Wrap" will enable the TextBlock to resize itself to display all the content.
TextBlocks have the TextTrimming property, so writing TextTrimming="WordEllipsis" will replace any cut off words with an ellipsis.
If you want to keep the one line but also show all the content, you can put the TextBlock inside a Horizontal ScrollViewer, which will let the user scroll the text left and right. Not great, but a decent solution
Code for 3.
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Visible">
<TextBlock Text="Text"/>
</ScrollViewer>
I added a huge right padding to my main TextBlock to work around this issue.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="MyTemplate">
<StackPanel VerticalAlignment="Top" Margin="0,-4,-50,0">
<TextBlock FontWeight="Bold" FontSize="18" Text="{Binding title}" TextWrapping="Wrap" Margin="0,0,0,6"/>
<TextBlock Text="{Binding text}" TextWrapping="Wrap" FontSize="30" Padding="0,0,125,0"/>
<Rectangle HorizontalAlignment="Stretch" Height="1" Fill="#78c5a6" Margin="0,18,0,18"/>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>

How to highlight a selected item in the LongListSelector on WP8?

How is it possible to highlight the selected item in the new LongListSelector on Windows Phone 8? Actually nothing happend if I tapped one entry of the list. My list only contains a simple string which will be displayed through a TextBlock. But I want to highlight the selection of the user.
Thanks.
In my case I used a RadioButtonControl in the DataTemplate of the LongListSelectorItem to achieve this. You will have a checked oder unchecked sign at the left border.
In any case it is important, that you set the same group for all Radiobuttons, so the selection only represents one entry.
Inside the Contentor your RadioButton you can put the TextBlock bound to the String.
Im currently not at home, but if this wont solve your problem, I'll provide you some code when I'm at home ;)
Here you go:
<LongListSelector.ItemTemplate>
<DataTemplate>
<ContentControl HorizontalAlignment="Stretch" HorizontalContentAlignment="Left">
<RadioButton HorizontalAlignment="Stretch" Margin="0,0,0,0" GroupName="A" Background="Black" >
<StackPanel toolkit:TiltEffect.IsTiltEnabled="True">
<TextBlock Text="{Binding Path=XXX}"
TextWrapping="Wrap"
Foreground="Black"
Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Path=XXXX}"
TextWrapping="Wrap"
Foreground="Black"
Margin="14,-6,0,0"
Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</RadioButton>
</ContentControl>
</DataTemplate>
</LongListSelector.ItemTemplate>

Categories