(1)xaml界面listbox代码
<ListBox ItemsSource="{Binding CurrentfeatureIds}" SelectedItem="{Binding CurrentFeature}" Grid.Row="6" Grid.Column="0" Margin="1">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=Image}" Height="14" Width="14" />
<TextBlock VerticalAlignment="Center" FontSize="14" Text="{Binding Text}" Margin="2,0,0,0"/>
</StackPanel>
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
(2)xaml.cs
public ObservableCollection<GridItem> GridList_Checked
{
get { return _gridList_Checked; }
set
{
_gridList_Checked = value;
OnPropertyChanged("GridList_Checked");
}
}
public ObservableCollection<FeatureIds> CurrentfeatureIds
{
get { return _currentfeatureIds; }
set
{
_currentfeatureIds = value;
OnPropertyChanged("CurrentfeatureIds");
}
}
(3)类
public class FeatureIds:BaseModel
{
/// <summary>
/// 要素id
/// </summary>
public int featureid { get; set; }
private bool _iserror;
/// <summary>
/// 是否有错
/// </summary>
public bool IsError
{
get
{
return _iserror;
}
set
{
_iserror = value;
OnPropertyChanged("IsError");
if(IsError==true)
{
Image = System.Windows.Forms.Application.StartupPath + @"\Images\SpotCheck\SignError.png";
}
else
{
Image = "";
}
}
}
/// <summary>
/// 错误信息
/// </summary>
public string ErrorMessage { get; set; }
/// <summary>
/// 显示信息
/// </summary>
public string Text
{
get { return "ID:" + featureid; }
set { }
}
private string ima;
/// <summary>
/// 图片
/// </summary>
public string Image
{
get
{
//ima = "";
//if (IsError ==true )
//{
// ima = System.Windows.Forms.Application.StartupPath + @"\Images\SpotCheck\SignError.png";
//}
return ima;
}
set
{
ima = value;
OnPropertyChanged("Image");
}
}
}
(4)界面