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![]()
Partager