Je lie une vue arborescente à l'aide d'une structure de classe Hiérarchique comme suit.Déclencheur Wpf pour modifier l'image d'un élément treeview
magasin -> ImagePath -> Liste -> Liste
Quand je crée le DataTemplate pour la personne, je veux utiliser une combinaison des person.name et le chemin d'image déclarée dans le Le magasin. Voici le code derrière mon fichier MainWindow.xaml. `partie publique partielle MainWindow: fenêtre { public MainWindow() { InitializeComponent();
Customers customers = new Customers();
customers.Users = new List<Person>
{
new Person { Name = "John"},
new Person { Name = "Adam"},
new Person { Name = "Smith"}
};
Store root = new Store();
root.ImagePath = "imageone.png";
root.Add(customers);
this.DataContext = root;
}
}
public class Store : ObservableCollection<Customers>
{
public string ImagePath
{
get;
set;
}
}
public class Customers
{
public string Label
{
get
{
return string.Format("People({0})", Users.Count());
}
}
public List<Person> Users
{
get;
set;
}
}
public class Person
{
public string Name
{
get;
set;
}
}`
et voici le xaml et cette Source = "{Binding Store.ImagePath}" ne fonctionne pas.
<Window.Resources >
<DataTemplate DataType="{x:Type local:Person}" x:Key="personKey" >
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding Store.ImagePath}"></Image>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
<HierarchicalDataTemplate x:Key="customerKey" ItemsSource="{Binding Users}" ItemTemplate="{StaticResource personKey }" >
<TextBlock Text="{Binding Label}" FontWeight="Bold"/>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<Canvas>
<Button HorizontalAlignment="Left" DockPanel.Dock="Top" Height="29" Width="112" Canvas.Left="123" Canvas.Top="5">Image one</Button> <Button HorizontalAlignment="Left" VerticalAlignment="Top" DockPanel.Dock="Top" Height="28" Width="119" Canvas.Left="249" Canvas.Top="7">Image two</Button>
<TreeView HorizontalAlignment="Stretch" Name="treeView1" VerticalAlignment="Stretch"
ItemsSource="{Binding .}" ItemTemplate="{StaticResource customerKey}" Height="260" Width="363" Canvas.Left="81" Canvas.Top="45" />
</Canvas>
</Grid>
Je voudrais aussi changer l'image programaticaaly et tous les éléments TreeView personne changer lorsque je clique sur des boutons.
Merci