Rasto
Rasto

Reputation: 17834

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

Upvotes: 0

Views: 702

Answers (1)

bsazonov
bsazonov

Reputation: 71

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

Upvotes: 1

Related Questions