Reputation: 8273
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
if (Convert.ToInt32(navigationParameter) >= 0)
{
BindData();
BindData();
txt1.Text = data[Convert.ToInt32(navigationParameter)].Name;
Img.Source = data[Convert.ToInt32(navigationParameter)].ImagePath;
}
i want to set img source as string .
Upvotes: 1
Views: 385
Reputation: 8273
myImage.Source = ImageFromRelativePath(this, "relative_path_to_file_make_sure_build_set_to_content");
public static BitmapImage ImageFromRelativePath(FrameworkElement parent, string path)
{
var uri = new Uri(parent.BaseUri, path);
BitmapImage result = new BitmapImage();
result.UriSource = uri;
return result;
}
Upvotes: 0
Reputation: 128061
You could write
Img.Source = new BitmapImage(new Uri(data[Convert.ToInt32(navigationParameter)].ImagePath));
UPDATE
In case ImagePath
is a relative path you may write it this way:
var path = data[Convert.ToInt32(navigationParameter)].ImagePath;
var uri = new Uri(path, UriKind.Relative);
Img.Source = new BitmapImage(uri);
Upvotes: 1