Change visible rectangle of content in ContentControl - c#

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" />

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

An user control as Tool tip for WPF TextBlock

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>

Scrollviewer panning position on touch

I have a scrollviewer in which I have 2 WrapPanels. I would like to know how I would go about getting the scroll viewer position once a user scrolled to the last end of the last panel. I am trying to show and hide an on screen arrow that indicates there is more content, but off to the right of the screen, but I would like to hide the button once they get to the end of the scroll viewer.
Can someone point me in the direction of what I would do in the code behind to get the horizontal offset position of the scrollviewer based on the panning. Mainly I want to get the far right position and hide the Arrow button when it gets to that point. My width for each Panel is currently 1920, so the window is currently 1920 width which hides the next panel in the Stack.
My XAML currently is below:
<ScrollViewer x:Name="scrVwrProductCategories" Style="{DynamicResource scrVwrFullWidthHorizontal}" PanningMode="HorizontalOnly" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled">
<StackPanel Width="Auto" Height="750" HorizontalAlignment="Right" Orientation="Horizontal">
<WrapPanel Style="{DynamicResource wrpPnlProductCategoriesPanels}" x:Name="wrpPnlProductCategories">
<!-- Constant currently for count of buttons per WrapPanel = 6-->
<!-- This is filled in dynamically at runtime
<controls:btnLarge Height="325" Width="500" Margin="20,0" TitleText="My Item" NoteText="" ShowNote="Collapsed" ShowSubTitle="Collapsed"/>
-->
</WrapPanel>
<WrapPanel Style="{DynamicResource wrpPnlProductCategoriesPanels}" x:Name="wrpPnlProductCategories2">
<!-- Constant currently for count of buttons per WrapPanel = 6-->
<!-- This is filled in dynamically at runtime
<controls:btnLarge Height="325" Width="500" Margin="20,0" TitleText="My Item" NoteText="" ShowNote="Collapsed" ShowSubTitle="Collapsed"/>
-->
</WrapPanel>
</StackPanel>
<Kiosk:SwipeForMoreArrow x:Name="ctrlSwipeForMoreArrow" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="Collapsed"/>
</ScrollViewer>
Do you aim to make this possible only through XAML? Otherwise you could try to get the this.HorizontalOffset of the Scrollviewer via the OnScrolledChanged Event to identify wether it´s 0 or max.
Maybe this link might help too:
How to find that ScrollViewer is scrolled to the end in WPF?

background of a part of ContentControl WPF

I want to get the background of spesific area of ContentControl.
Here is my ContentControl ;
The area I would like to have is (topright of the ContentControl) ;
How can I do that?
Put your content control into another content control and set the horizontal and vertical position to topright. In the following example I use an image in a grid.
<Grid>
<Image
x:Name="MyImage"
Height="22"
HorizontalAlignment="Right"
Margin="10"
VerticalAlignment="Top"
Width="22" />
</Grid>

Aligning Button and multiline textblock in Stack panel Silverligh

Here is the scenarion:
---------- ++++++++++++
--Button-- +Text block+
---------- ++++++++++++
In WPF is extremely easy with a dock panel. What is the way to achieve this in Silverlight.
Try a StackPanel and make its orientation Horizontal. You can then adjust the vertical and horizontal alignment of the stack panel's children to your needs.
ie:
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="High" VerticalAlignment="Center"></Button>
<TextBlock Margin="10" Width="100" Text="Insert Text Here" TextWrapping="Wrap" VerticalAlignment="Center"/>
</StackPanel>
You can use the DockPanel in Silverlight too, thanks to the Silverlight toolkit.
After installing the toolkit you can add the following namespace in your XAML:
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
Then in your element's attributes add:
toolkit:DockPanel.Dock="Right"
Of course change "Right" to: Right, Left, Top, or Bottom as needed.

Categories

Resources