re-bonjour

c'est encore moi

voici donc un petit source sympa

pour le xaml
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
 
<Window x:Class="SentinelSAS.Window3"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:Local="clr-namespace:SentinelSAS"
    Title="TestLogger" Height="488" Width="760">
    <Window.Resources>
        <Local:TestCollection x:Name="Tests" x:Key="Tests" />
 
        <Style TargetType="{x:Type ListViewItem}" x:Key="myListViewItemStyle">
            <Setter Property="Height" Value ="100"/>
        </Style>
 
    </Window.Resources>
 
    <Grid>
        <ListView ItemsSource="{Binding Source={StaticResource Tests}}"
                  x:Name="listView1"
                  ItemContainerStyle="{StaticResource myListViewItemStyle}"
                  >
            <ListView.View>
                <GridView AllowsColumnReorder="True">
                    <GridViewColumn 
                        Width="{Binding 
                            RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, 
                            Path=ActualHeight}"
                        >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Ellipse x:Name="el"
                                    Width="{Binding RelativeSource={RelativeSource FindAncestor,
                                        AncestorType={x:Type ListViewItem}}, Path=ActualHeight}"
                                    Height="{Binding ElementName=el, Path=Width}" 
                                    Stroke="Black">
                                </Ellipse>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Nom" DisplayMemberBinding="{Binding Path=Nom}" Width="150"/>
                    <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}" Width="150"/>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>
et celui ci pour la fenetre
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
56
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
 
namespace SentinelSAS
{
    /// <summary>
    /// Logique d'interaction pour Window3.xaml
    /// </summary>
    public partial class Window3 : Window
    {
        public Window3()
        {
            InitializeComponent();
            TestCollection pc = this.Resources["Tests"] as TestCollection;
            pc.Add(new Test { Nom = "alpha 1", Age = 10 });
            pc.Add(new Test { Nom = "alpha 2", Age = 25 });
            pc.Add(new Test { Nom = "alpha 3", Age = 50 });
            pc.Add(new Test { Nom = "alpha 4", Age = 15 });
            pc.Add(new Test { Nom = "alpha 5", Age = 22 });
            pc.Add(new Test { Nom = "alpha 6", Age = 65 });
            pc.Add(new Test { Nom = "alpha 7", Age = 65 });
            this.listView1.DataContext = pc;
        }
    }
 
    public class Test
    {
        private string _Nom = "";
        public string Nom
        {
            get { return _Nom; }
            set { _Nom = value; }
        }
        private int _Age = 0;
        public int Age
        {
            get { return _Age; }
            set { _Age = value; }
        }
    }
    public class TestCollection : ObservableCollection<Test>
    {
    }
}
voici donc mon nouveau probleme :
j'aimerais binder le width de mon GridViewColumn
soit sur le height de mon style

<Style TargetType="{x:Type ListViewItem}" x:Key="myListViewItemStyle">
<Setter Property="Height" Value ="100"/>
</Style>

defini dans les resources

soit sur le ActualHeight des ListViewItem c'est d'ailleurs ce que j'ai ecrit

Width="{BindingRelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}},Path=ActualHeight}"

mais semble t'il cela ne fonctionne pas vraiment ...
c'est etonnant d'ailleurs puisque qu'en bindant l'ellipse (width, height) sur ce meme listviewitem cela fonctionne

kekun a une tite idee ?