An user control as Tool tip for WPF TextBlock - c#

I have a TextBlock having a canvas as its ToolTip. An user control is bounded to the canvas from the back-end in constructor. The TextBlock defined in xaml as follows:
<TextBlock Width="60" Height="40" Text="More info.">
<TextBlock.ToolTip>
<Canvas Name="canToolTip"></Canvas>
</TextBlock.ToolTip>
</TextBlock>
The constructor definition will be :
public UC_PublicationAdd()
{
InitializeComponent();
// assign datacontext
canToolTip.Children.Add(new ToolTipControl());
}
The whole scenario is fine Now let me come to the Problem. When i place the mouse over the TextBlock ToolTip is showing but its size is not controllable. What i mean is that, size of tooltip is too smaller(default size when tooltip text is not present). I want the tooltip equal to the size of the canvas

Sorry for Make you Confused, finally i solved the issue by assigning width and height to the canvas inside the tooltip. The xaml looks like the following:
<TextBlock Width="60" Height="40" Text="More info.">
<TextBlock.ToolTip>
<Canvas Name="canToolTip" Height="80" Width="130"></Canvas>
</TextBlock.ToolTip>
</TextBlock>

Related

How to scale font size to fit the window if it's larger than the window in WPF XAML?

Not sure if this is hard to do in XAML, but I have some TextBlock that I am showing on top of the main window using a fixed font size.
If this is larger than the main window, it resizes the main window. I don't want this. I tried this so far but couldn't prevent the main window from getting resized horizontally.
What I want is to resize the TextBlock if it's not going to fit the main window width. Main window width is dynamic so I can't use a fixed unit value.
Here is the code:
<Viewbox StretchDirection="DownOnly">
<Grid Name="InfoTextOverlay" Visibility="Hidden" HorizontalAlignment="Center">
<TextBlock Text="{Binding InfoText, ElementName=MyMainWindow}" Foreground="White" FontSize="40" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Viewbox>
if you want to avoid auto width, use TextWrapping="Wrap".
or
Just remove the FontSize property if you need auto-resizing of the text block

WPF textBox changes color halfway

I have a strange problem with the textBox in WPF. I have a simple textbox inside a stackpanel binded with some text on the code behind. When the text becomes too long some part of it changes color. Here is an example
The stackpanel is this
<StackPanel Canvas.Left="50" Canvas.Top="111">
<TextBlock Text="{Binding Title}" FontSize="32" Foreground="White" />
<TextBlock Text="{Binding Subtitle}" FontSize="15" Foreground="#9EA3AA"/>
</StackPanel>
How can I make all the text white?
As mentioned by Clemens you are experiencing overlap. To fix this make the cell containing the orange cpu image and text not extend so high. You should be able to just drag and drop.

how to give height of a parent to child in UWP

I have a stack panel and it has one grid and I'd like the grid to have same height as stack panel.
I tried playing with VerticalAlignment stretch or height 100% nothing works
I tried setting the values programatically OnNavigatedTo but it doesn't have the effect
Any suggestions to resolve this are welcome
Please find the code below
<StackPanel Grid.Row="0" Grid.RowSpan="4" Background="#CFFF" Visibility="Visible" Orientation="Vertical" Name="ProgressOverlay">
<Grid Name="Overlaygrid"">
<StackPanel VerticalAlignment="Center" Grid.Row="0">
<ProgressBar
IsIndeterminate="True"
IsEnabled="True" Foreground="Black"/>
<TextBlock Visibility="Visible" Foreground="Black" FontSize="25” T HorizontalAlignment="Center" Text="Loading"/>
</StackPanel>
</Grid>
</StackPanel>
A StackPanel takes by default the size needed by its content and shrinks to the size required, while a container control like Grid stretches to the full size available (e.g full page).
If you want to keep the outer StackPanel, you will have to set VerticalAlignment="Stretch" on the StackPanel, not on the Grid.
But since the Grid is the only single content item in your outer StackPanel, you can remove it and move the properties Grid.RowSpan="4" Background="#CFFF" Visibility="Visible" to the Grid. Always try to keep your XAML structure as simple as possible.

XAML WP8 and making a 'TextBlock' scroll down

Alright, so I have a XAML page with a TextBlock in a Windows Phone 8 application. My dilemma is this:
I pragmatically add more content (formatted lines with Inlines.Add(new Run...) to the TextBlock. The text block is currently filled from bottom to up because of the ScrollViewer in the sense that a line appears in the bottom after another. I would also be fine with them starting to appear from the top as long as the TextBlock would continue to scroll down (actually this might look better) once it is full. My TextBlock is inside a ScrollViewer as below:
<Popup x:Name="send_message_xaml" Grid.Row="1" VerticalOffset="0" Width="750" Height="auto">
<StackPanel Orientation="Vertical" Margin="0,0" Width="auto" Height="auto">
<ScrollViewer Height="345" HorizontalAlignment="Left" Margin="0,0,0,0" Name="scrollViewer1" VerticalAlignment="Bottom" Width="420" VerticalScrollBarVisibility="Auto">
<TextBlock x:Name="message_log" Margin="40,50,0,0" TextWrapping="Wrap" Width="420" VerticalAlignment="Top" FontSize="22"/>
</ScrollViewer>
<TextBox x:Name="message_to_send" InputScope="Chat" Width="480" KeyDown="message_to_send_KeyDown" Margin="15,0"/>
</StackPanel>
</Popup>
How can I get the textblock to scroll so that the newest appended message is always at the bottom? I found a bunch of these threads but none seem to solve my problem so far. Do I need to add some code somewhere with the appending?
You need to update the VerticalOffset based on the ScrollableHeight. When you add new inlines to the TextBlock, its height is going to change and that will notify the parent ScrollViewer. So, after you add new items to the inlines, run the Measure method and update the VerticalOffset.
Here is an example.

Change visible rectangle of content in ContentControl

In WPF I have ContentControl that has limited size (lets say 100x30). A Content of this ContentControl is a Label of size 200x30 so the whole Label cannot be visible within the ContentControl.
How can I programatically set which area of the Label is visible in ContentControl ? The visible area (rectangle) of the content may change over time. Can I do this without using ScrollViewer (just to set visible clip) ?
EDIT: Well then, I am not even able to do it using ScrollViewer so any advice on that would be appriciated as well
You can place your label on canvas and move it using Canvas.Left property.
Small example where label's position is adjusted using binding to a slider Value property.
<ContentControl Width="100" Height="30">
<Canvas ClipToBounds="True">
<Label Canvas.Left="{Binding ElementName=mySlider, Path=Value}" Width="200" Height="30">Here is some very long sample text </Label>
</Canvas>
</ContentControl>
<Slider Name="mySlider" Minimum="-200" Maximum="100" />

Categories

Resources