Hello,
J'ai un contrôle Image qui est bindé sur mon ViewModel de la manière suivante:
Cette image a sa BuildAction à Content et je souhaiterais lire les dimensions depuis le constructeur du ViewModel afin d'affecter les bonnes valeurs aux propriétés ActualWidth et ActualHeight ci-dessus.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <Canvas x:Name="Canvas1" Grid.RowSpan="3" Grid.Row="0" Grid.ColumnSpan="2" Grid.Column="0"> <Image x:Name="Image1" Source="{Binding Path=URL, Converter={StaticResource StringToBitmapConverter}}" Width="{Binding Path=ActualWidth,Mode=TwoWay}" Height="{Binding Path=ActualHeight,Mode=TwoWay}"> <Image.RenderTransform> <CompositeTransform ScaleX="{Binding Path=ScaleX,Mode=TwoWay}" ScaleY="{Binding Path=ScaleY,Mode=TwoWay}" TranslateX="{Binding Path=TranslateX,Mode=TwoWay}" TranslateY="{Binding Path=TranslateY,Mode=TwoWay}"> </CompositeTransform> </Image.RenderTransform> </Image> </Canvas>
J'ai donc créer une méthode qui me fait ça:
Mais ça me renvoi toujours 0,0 !!!
Code : 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 private Point GetImageDimensions(string ImageURL) { var Store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if(Store == null) { return new Point(0,0); } if(ImageURL == string.Empty) { return new Point(0,0); } else { if(!Store.FileExists(ImageURL) || ImageURL == string.Empty) { return new Point(0,0); } else { using(System.IO.IsolatedStorage.IsolatedStorageFileStream CurrentIsolatedStorageStream = Store.OpenFile(ImageURL,System.IO.FileMode.Open)) { if(CurrentIsolatedStorageStream.Length > 0) { BitmapImage CurrentBitmap = new BitmapImage(); CurrentBitmap.SetSource(CurrentIsolatedStorageStream); CurrentIsolatedStorageStream.Close(); return new Point(CurrentBitmap.PixelWidth,CurrentBitmap.PixelHeight); } else { return new Point(0,0); } } } } }
Je ne vois pas pourquoi ....
Merci
Partager