Bonjour à tous,
J'ai le code suivant:
et
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 <Window x:Class="test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:test" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="5"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <StackPanel Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Button_Click" /> </StackPanel> <GridSplitter Grid.Column="1" VerticalAlignment="Stretch" Width="5" ShowsPreview="True" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" /> <ListBox Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="lstDocuments" ScrollViewer.HorizontalScrollBarVisibility="Disabled" > <ListBox.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="{x:Static local:MainWindow.MaxColumn }"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Image Source="{Binding img}" Grid.Column="{Binding col}" Grid.Row="{Binding row}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid> </Window>
Je voudrais faire binding de la propriété "Columns" du "UniformGrid" sur la propriété "MaxColumn " de ma classe principale pour pouvoir l'initialiser à partir de mon fichier ini.
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 namespace test { /// <summary> /// Logique d'interaction pour MainWindow.xaml /// </summary> public partial class MainWindow : Window { public int MaxColumn { get; set; } public class toto { public BitmapImage img { get; set; } } public ObservableCollection<toto> lstElem { get; set; } public MainWindow() { InitializeComponent(); MaxColumn = 5; lstElem = new ObservableCollection<toto>(); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(@"D:\Pompotte 1.jpg"); bitmap.EndInit(); toto t = new toto(); t.img = bitmap; lstElem.Add(t); bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(@"D:\Pompotte 2.jpg"); bitmap.EndInit(); toto t2 = new toto(); t2.img = bitmap; lstElem.Add(t2); bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(@"D:\20150919 - Casper - 1.jpg"); bitmap.EndInit(); toto t3 = new toto(); t3.img = bitmap; lstElem.Add(t3); lstDocuments.ItemsSource = lstElem; }
J'ai essayé plusieurs solutions mais j'ai toujours le message d'erreur comme de quoi il ne trouve pas ma propriété MaxColumn. Une idée ?
Partager