WPF ViewBox Zoom

Is there a way to increase the size of the view content, excpet for a single control? I have a viewbox with a grid and in that grid I have some controls and I am trying to enlarge all the controls in the viewport except one, is this possible?

Thanks a lot, Paulo

+2


source to share


1 answer


You can use the grid to add layers to your layout. Thus, you can enlarge one set of elements and leave the other set without enlarging.

<Grid>
  <Viewbox>
    <!-- Controls to zoom -->
  </Viewbox>
  <!-- Control to exclude from zoom -->
</Grid>

      

The order of the viewport and other controls in XAML will depend on which layer appears on top.

If this is not exactly what you want, please leave a comment and I will come back to the answer.

EDIT . You want the unzoomed control to be positioned relative to (0,0) Viewbox

. This will happen in this situation because both children of the grid are at cell (0,0), which means that their top-left corners are aligned. Can you provide an example of what you have in XAML and what is wrong with it (maybe edit the original question)?

Here's some XAML to try:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <TextBlock>I am positioned at (0,0)</TextBlock>
    <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
  </Grid>
</Page>

      

This gives a layout like this:



http://img20.imageshack.us/img20/2045/layout1m.png

But note that as the height decreases, the grid becomes wider than the viewport and therefore the content is laid out like this:

http://img20.imageshack.us/img20/9397/layout2i.png

I guess this is not what you want. In this case, you use a canvas and move on to the next:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Background="Green">
  <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox>
      <Rectangle Fill="Yellow" Width="10" Height="10" />
    </Viewbox>
    <Canvas>
      <TextBlock>I am positioned at (0,0)</TextBlock>
      <TextBlock Margin="50,50">I am positioned at (50,50)</TextBlock>
    </Canvas>
  </Grid>
</Page>

      

Which looks like this:

http://img20.imageshack.us/img20/6743/layout3i.png

+5


source







All Articles