Reputation: 3485
I have a list box XAML of which looks like this
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<ListBox HorizontalAlignment="Left" Margin="12,12,0,0" Name="ComplaintslistBox" VerticalAlignment="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="400" BorderThickness="1">
<Button.Content>
<StackPanel Orientation="Horizontal">
<StackPanel>
<Image Source="{Binding Type}" Width="30" Height="30"></Image>
</StackPanel>
<StackPanel>
<TextBlock Text="{Binding Head}" Width="300"></TextBlock>
</StackPanel>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
now the problem is it is binding "Head" but not binding the "Type"
Type variable contains path to the image which is to be shown....
class looks like this
public class Complaints
{
public string Id { get; set; }
public string Type { get; set; }
public string Head { get; set; }
//public string Desc { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string wardNo { get; set; }
public string wardName { get; set; }
public string creator { get; set; }
public string url { get; set; }
public string catId { get; set; }
public string subCatId { get; set; }
public int commentCount { get; set; }
public int solutionCount { get; set; }
public int affectedCount { get; set; }
public Complaints() { }
public Complaints(Complaints complaints)
{
this.Id = complaints.Id;
this.Head = complaints.Head;
//this.Desc = complaints.Desc;
switch (complaints.Type)
{
case "Reported":
this.Type = "icons/icon_red.png";
break;
case "Reopened":
this.Type = "icons/icon_black.png";
break;
case "Resolved":
this.Type = "icons/icon_green.png";
break;
default:
this.Type = "icons/icon_blue.png";
break;
}
this.wardNo = complaints.wardNo;
this.wardName = complaints.wardName;
this.lat = complaints.lat;
this.lon = complaints.lon;
this.catId = complaints.catId;
this.subCatId = complaints.subCatId;
this.url = complaints.url;
this.creator = complaints.creator;
this.affectedCount = complaints.affectedCount;
this.commentCount = complaints.commentCount;
this.solutionCount = complaints.solutionCount;
}
}
Thanks
Upvotes: 0
Views: 610
Reputation: 137108
Binding to an ImageSource
might be easier than binding to a string
.
You'll need something like this:
var ISC = new System.Windows.Media.ImageSourceConverter();
this.Type = (ImageSource)ISC.ConvertFromString(ImagePath);
where Type is:
public ImageSource Type { get; set; }
rather than string
.
Upvotes: 1
Reputation: 184306
The question is where those images are located, if those are resources in the assembly you need to qualify the path using Pack URI syntax, in fact it can never hurt to fully qualify the path. So if you use resources it should be something like:
"pack://application:,,,/icons/icon_red.png"
Upvotes: 0