Hi all,
I have some problem on databinding to Image's Source Property.
I have a listview Template
<Style x:Key="ListViewStyle" TargetType="{x:Type ListView}">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate x:Key="ListViewItemTemplate">
<StackPanel Width="60" Margin="5,5,10,5">
<Image Height="40" Width="40" Source="{Binding XPath=@Image}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding XPath=@Name}" TextAlignment="Center" TextWrapping="Wrap" FontWeight="bold" HorizontalAlignment="Center" Margin="0,0,0,1" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
This Style is defined in a Resource Dictionary File which is added in app.xaml. (So is accessible anywhere)
Now I have a window in which I have used this style for listview. In Winodw.Resources I have created an xmldatasource provider
<XmlDataProvider x:Key="MyData" XPath="/Reports">
<x:XData>
<Reports xmlns="">
<Item Name = "Item1" Image="Resources\MenuIcons\Pic1.png"/>
<Item Name = "Item2" Image="Resources\MenuIcons\Pic2.png"/>
<Item Name = "Item3" Image="Resources\MenuIcons\Pic3.png"/>
</Reports>
</x:XData>
</XmlDataProvider>
and I have assigned this datasource as Itemsource for Listview
<ListView Name="MyListView" Style="{DynamicResource ListViewStyle}" ItemTemplate="{StaticResource ListViewItemTemplate}"
ItemsSource="{Binding Source={StaticResource MyData},XPath=Item}"/>
My Problem is when I run application ListViewItem's Text is Displaying But Image is missing..
But When I Defined this Style inside Window.Resource and used Style as StaticResource instead of Dynamic Resource, everything works fine.
Can Anybody tell me reason for not desplaying image? I want to use this style Globally.(So I need to define it in ResourceDictionary). Can anyone help me??