1 回答

TA貢獻1809條經(jīng)驗 獲得超8個贊
如果我很好地理解您需要什么,您可以使用一個轉(zhuǎn)換器,使用“EmployeeID”將為您返回一個 ImageSource:
class Imageconverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
string imgDir = @"\Imgs\";
string fileName = System.IO.Path.Combine(imgDir,String.Format("{0}.jpg", value.ToString()));
if (!System.IO.File.Exists(fileName))
return null;
BitmapImage src = new BitmapImage(new Uri(fileName, UriKind.Absolute));
return src;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
為轉(zhuǎn)換器創(chuàng)建資源:
<local:Imageconverter x:key="ImgConverter/>
并使用它:
<Image Name="employeeImage" Grid.Column="0" Width="50"
Source="{Binding EmployeeID, Converter={StaticResource ImgConverter}}"/>
- 1 回答
- 0 關(guān)注
- 141 瀏覽
添加回答
舉報