Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fit in Viewbox
Message
De
13/04/2009 13:22:24
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Fit in Viewbox
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01394627
Message ID:
01394627
Vues:
111
Hi,

Simplest way to explain my requirements will be a simple example. So:
<Window x:Class="WpfApplication1.Window23"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <StackPanel Orientation="Vertical">
    <Canvas x:Name="Outer" Height="500" Width="500" Background="AliceBlue">
        <Canvas x:Name="Main" Height="200" Width="200" Background="Red" Canvas.Top="200" ClipToBounds="True" >
                <Canvas.RenderTransform>
                    <RotateTransform Angle="345" />
                </Canvas.RenderTransform>
                    <Canvas x:Name="Contained" Height="300" Width="300" Background="Yellow" Canvas.Top="50" Canvas.Left="50">
                <Canvas.RenderTransform>
                    <RotateTransform Angle="345"/>
                </Canvas.RenderTransform>
            </Canvas>
        </Canvas>
    </Canvas>
        <Border BorderBrush="Black" BorderThickness="2" Width="96" Height="96">
        <Viewbox x:Name="VBox"  >
        </Viewbox>
            </Border>
        <Button Click="Button_Click">Thumbnail it</Button>
  </StackPanel>
</Window>
Code:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApplication1
{
  
    public partial class Window23 : Window
    {
        public Window23()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Outer.Children.Remove(Main);
            Main.LayoutTransform = Main.RenderTransform;
            Main.RenderTransform = Transform.Identity;
            VBox.Child = Main;
        }
    }
}
This does what I want. However if ClipToBounds is not set on Main then the sizing is obviously wrong. Whats the simplest way of getting this right?

I originally did this without using a ViewBox by using GetDescendantBounds, adding a ScaleTransform etc. It worked OK but got pretty ugly - basing the operation around a ViewBox should be much simpler.

Any suggestions,
Viv
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform