IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Dé-zoom automatique sur un Canvas pour voir tous ses éléments


Sujet :

Windows Presentation Foundation

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mars 2010
    Messages
    57
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 57
    Points : 38
    Points
    38
    Par défaut Dé-zoom automatique sur un Canvas pour voir tous ses éléments
    Bonjour à tous,

    je bloque sur un problème quant à l'affichage d'éléments d'un canvas. Je vous explique:

    J'ai un control qui est le suivant
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    <UserControl x:Class="MyApplication.Views.MyView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:Views="clr-MyApplication.Views" mc:Ignorable="d" 
                 IsManipulationEnabled="True"
                 Width="1900" Height="1380"
                 >
        <UserControl.RenderTransform>
            <MatrixTransform></MatrixTransform>
        </UserControl.RenderTransform>
        <Border BorderBrush="Gray" BorderThickness="4" CornerRadius="5">
            <Grid Background="Transparent" Name="Root">
                <Grid.Resources>
                    <Style x:Key="ContainerStyle">
                        <Setter Property="Canvas.Left" Value="{Binding Left}" />
                        <Setter Property="Canvas.Top" Value="{Binding Top}" />
                    </Style>
                </Grid.Resources>
                <ItemsControl Name="map" ItemsSource="{Binding MyObjects}"
                              ItemContainerStyle="{StaticResource ContainerStyle}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas ClipToBounds="True"  Background="Gray" Margin="5"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Views:MyObjectView DataContext="{Binding}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
     
            </Grid>
        </Border>
    </UserControl>

    qui est censé m'afficher ma liste d'objets placé dans un canvas.
    Le problème est que certains de mes objets, une fois placé, "sortent" de l'écran .

    Après quelque recherches, j'ai trouvé un bout de code qui devrait marcher, cependant je ne vois pas encore tous mes objets sur le canvas :/.

    Voici la fenetre
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    <Window x:Class="MyApplication.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            xmlns:local="clr-namespace:MyApplication"        
            xmlns:Controls="clr-namespace:MyApplication.Controls"
            xmlns:Views="clr-namespace:MyApplication.Views"
            xmlns:ViewModels="clr-namespace:MyApplication.ViewModels"
            Title="MainWindow" 
            Width="1024" Height="600"
            WindowStartupLocation="CenterScreen"  
            WindowState="Maximized"
            WindowStyle="None"
            KeyDown="Window_KeyDown"
            Background="{DynamicResource WindowBackgroundBrush}"
            >
    <Grid x:Name="LayoutRoot" Margin="10">
    <Controls:TouchableContainer 
                            x:Name="zoomControl" 
                            ClipToBounds="True" 
                            Background="GhostWhite" 
                            Margin="5" >
                        <Views:MyView x:Name="myControl"
                                         DataContext="{Binding }"/>
                    </Controls:TouchableContainer>
     </Grid>
    </Window>

    et le code behind:
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
     
     
    private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
            {
                if (e.Key == Key.F12)
                {
                    Close();
                }
     
                if (e.Key == Key.F2)
                {
                    FillToParent();
                }
            }
    public void FillToParent()
            {
                double heigth = myControl.ActualHeight;
                double width = myControl.ActualWidth;
     
                double heigthC = zoomControl.ActualHeight;
                double widthC = zoomControl.ActualWidth;
     
                double heightRation = heigth / heigthC;
                double widthRation = width / widthC;
     
                if (heigth > heigthC)
                    heightRation = heigthC / heigth;
                if (width > widthC)
                    widthRation = widthC / width;
     
                Matrix matrice = ((MatrixTransform)myControl.RenderTransform).Matrix;
                double x = -(double)myControl.GetValue(Canvas.TopProperty);
                if (double.IsNaN(x))
                    x = 0;
                double y = -(double)myControl.GetValue(Canvas.LeftProperty);
                if (double.IsNaN(y))
                    y = 0;
     
                double deltaX = 0;
                double deltaY = 0;
                if (widthRation < heightRation)
                {
                    deltaY = Math.Abs((heigthC - heigth * widthRation) / 2);
                }
                if (heightRation < widthRation)
                {
                    deltaX = Math.Abs((widthC - width * heightRation) / 2);
                }
     
                matrice.OffsetX = x + deltaX;
                matrice.OffsetY = y + deltaY;
                matrice.M11 = Math.Min(heightRation, widthRation);
                matrice.M22 = Math.Min(heightRation, widthRation);
                matrice.M12 = 0;
                matrice.M21 = 0;
                myControl.RenderTransform = new MatrixTransform(matrice);
            }

    Je viens donc quémander , si quelqu'un a une idée concernant ce problème?
    Un grand merci pour toute l'aide que vous pourrez m'apporter

  2. #2
    Nouveau membre du Club
    Inscrit en
    Mars 2010
    Messages
    57
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 57
    Points : 38
    Points
    38
    Par défaut
    Bon et bien, j'ai trouvé tout seul.

    Cela venait du fait que mon control avait une taille fixe

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <UserControl x:Class="MyApplication.Views.MyView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:Views="clr-MyApplication.Views" mc:Ignorable="d" 
                 IsManipulationEnabled="True"
                 Width="1900" Height="1380"
                 >

    Du coup il ne pouvait jamais tout affiché

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 30/10/2012, 15h44
  2. Réponses: 4
    Dernier message: 06/03/2009, 16h39
  3. [Joomla!] ajouter un lien pour voir tous les items
    Par htr999 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 9
    Dernier message: 24/05/2008, 18h22
  4. Quel langage pour un script qui connecte automatiquement sur un site ?
    Par dephesity dans le forum Langages de programmation
    Réponses: 6
    Dernier message: 13/08/2007, 11h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo