show image on GridView win 8 metro style? - windows-8

I follow step by step this article(http://mikaelkoskinen.net/winrt-step-by-step-tutorial-mvvm-gridview-semanticzoom/) to add Images to GridView of my project, but when I finish adding GridView to my project following this article. I had a problem with showing image is that the image( in the project folder) don't show when the app is running but the app shows images from internet(the code from article has run well and loaded the image from project folder), I don't know how to show this problem,
this is some code:
public class Movie
{
public string Title { get; set; }
public string Subtitle { get; set; }
public string Image { get; set; }
public string Category { get; set; }
}
public class MovieCategory
{
public string Title { get; set; }
public List<Movie> Items { get; set; }
}
My code to load image from project folder:
MovieList.Add(new Movie { Title = "The Ewok Adventure", Category = "Adventure", Subtitle = "The Towani family civilian shuttlecraft crashes on the forest moon of Endor.", Image = "duy.jpg" });
(I've create MovieList before, and image "duy.jpg" is in the folder of project)
I don't why I try above code with source from article,i've checked image source string carefully by debug tool, it worked well(image from project folder was showed in source of article) but when i added to my project,the image from internet link worked well but the image from project folder didn't load.
Please help me.Thank in advance.

Change class definition like this
public class Movie
{
public string Title { get; set; }
public string Subtitle { get; set; }
public string Image { get; set; }
public string Category { get; set; }
public ImageSource ImgSource
{
get
{
return new BitmapImage(new Uri("ms-appx:///" + this.Image));
}
}
}
And bind Image tag with ImgSource property not with Image property.
<Image Source="{Binding ImgSource}" ........./>

is the image in project root ? did you set to Content and Always copy to output folder ?

Related

Controller scaffolding doesn't work in VS 2017 preview for ASP.NET Core 2 Preview

I'm trying to use scaffolding to generate MVC Controller with views, using Entity Framework:
I created ApplicationDBContext:
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<med1.Models.House> House { get; set; }
}
and added to ConfigureServices:
services.AddDbContext<Data.ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
And of course I have House model:
public class House
{
public int ID { get; set; }
public string HouseName { get; set; }
public string Address1 { get; set; }
public int CityID { get; set; }
public City City { get; set; }
public string ZIP { get; set; }
public int StateID { get; set; }
public State State { get; set; }
}
I got following error:
Okay, I added parameterless constructor to ApplicationDBContext:
public ApplicationDbContext() { }
And got the following error:.
Actually I had the same problem with previous project and created Controller and View manually.
But for this project I'd like to use scaffolding.
I'm doing something wrong or it's VS 2017 preview problem?
You may be missing this part -
public class AppDbContextFactory : IDbContextFactory<AppDbContext>
{
public AppDbContext Create(string[] args) =>
Program.BuildWebHost(args).Services.GetRequiredService<AppDbContext>();
}
Once you enable scaffolding in your ASP.NET Core 2.0 project and created model name as 'House', follow these steps-
Step1: Right click on the Controllers folder in Solution Explorer and select Add > New Scaffolded Item.
Step2: Select 'MVC Controller with View, using Entity Framework' and click on Add.
Step3: In Add Controller, select House Model and use plus(+) sign to create new AppDbContext. It will also add above mentioned AppDbContextFactory.
After finishing step3, you will have HousesController in Controllers folder and corresponding Houses folder inside views folder.
This is my AppDbContext looks like-
public class AppDbContext : DbContext
{
public AppDbContext (DbContextOptions<AppDbContext> options)
: base(options)
{
}
public DbSet<AspNetCore200_VS2017preview1_scaffolding.Models.House> House { get; set; }
}
Hope this helps to proceed further.
Copy contents of the following path of your application
"bin\Debug\netcoreapp1.1"
to
"bin\MCD\Debug\netcoreapp1.1"
This solved the issue for me

Delegate the property display name translation to a handler

Current code in model:
[Display(Name = "E-mail")]
public string EMail { get; set; }
Desired code:
public string EMail { get; set; }
I would like to delegate the translation to a handler, something like this:
if(propertyName == "EMail") return "E-mail"
Based on my understanding of your question, I'm assuming that you are trying to implement localisation in your application.
If so, there are two options;
Resources
In .NET you can add Resource (.resx) files into your application to handle translation (one resx for each language). Then you can specify the Resource by specifying the ResourceType property of your Display attribute. For example;
public class Model
{
[Display(Name = "Email", ResourceType = typeof(Resources.Strings))]
public string Email { get; set; }
}
Custom attribute
Alternatively, if you are set on implementing this in a handler then you could implement a custom attribute, as demonstrated in this question.
Edit: Modified from the example in the above post.
If you add a new Resource file to your project - say Strings.resx and add "HelloWorld" as a field. You can then create a new attribute, such as LocalisedDisplayNameAttribute;
public class LocalisedDisplayNameAttribute : DisplayNameAttribute
{
public LocalisedDisplayNameAttribute(string resourceId)
: base(GetMessageFromResource(resourceId))
{
}
private static string GetMessageFromResource(string resourceId)
{
// "Strings" is the name of your resource file.
ResourceManager resourceManager = Strings.ResourceManager;
return resourceManager.GetString(resourceId);
}
}
You can then use it as follows;
public class Model
{
[LocalisedDisplayName("HelloWorld")]
public string Email { get; set; }
}
Let me know if I can help further,
Matt

Json parsing in windows phone (C#)

I am new to Windows Phone development.I want to parse some data using json parsing.After
googling i find a number of example but I am not able to understand properly.I have follow
a link
http://dotnetbyexample.blogspot.in/2012/01/json-deserialization-with-jsonnet.html
to do json parsing But i am not able to show Storage ,Memory, ScreenSize in my List and my code is
private void Load_Click(object sender, RoutedEventArgs e)
{
var w = new WebClient();
Observable
.FromEvent<DownloadStringCompletedEventArgs>(w, "DownloadStringCompleted")
.Subscribe(r =>
{
var deserialized =
JsonConvert.DeserializeObject<List<RootObject>>(r.EventArgs.Result);
PhoneList.ItemsSource = deserialized;
});
w.DownloadStringAsync(
new Uri("http://www.schaikweb.net/dotnetbyexample/JSONPhones1.txt"));
}
}
public class Specs
{
public string Storage { get; set; }
public string Memory { get; set; }
public string Screensize { get; set; }
}
public class RootObject
{
public string Brand { get; set; }
public string Type { get; set; }
public Specs Specs { get; set; }
}
}
Please Help me to solve this issue or any other sample for the same is also appreciated
Thanks
The code seems ok, so if you aren't running in to any errors there might be an issue with your UI code or UI to data coupling.
You need to post the UI code to get some help with this I suspect.

WkHtmlToXSharp How to add Headers and Footers?

I'm building an HTML to PDF converter with the WkHtmlToXSharp (QT webkit) library, and was wondering if someone knows how to add headers and footers to the document? I've seen a few questions about this library here, but couldn't find anything about the headers and footers.
In the wkhtmltopdf manual (http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html) there are documentation about headers and footers, but I couldn't find anything in the .NET wrapper library (WkHtmlToXSharp), it is probably not implemented?
Thanks for any help or suggestions!
Here are some snippets of how I do it:
public class HeaderFooterSettings
{
public string HtmlUrl { get; set; }
public string Right { get; set; }
public string Spacing { get; set; }
}
public class PdfObjectSettings
{
private WebSettings _webSettings = new WebSettings();
private LoadSettings _loadSettings = new LoadSettings();
private HeaderFooterSettings _headerSettings = new HeaderFooterSettings();
private HeaderFooterSettings _footerSettings = new HeaderFooterSettings();
public string Page { get; set; }
public string Cover { get; set; }
public bool ProduceForms { get; set; }
public bool PagesCount { get; set; }
public HeaderFooterSettings Header { get { return _headerSettings; } }
public HeaderFooterSettings Footer { get { return _footerSettings; } }
public WebSettings Web { get { return _webSettings; } }
public LoadSettings Load { get { return _loadSettings; } }
// TODO: Add remaining settings..
//see the following page for settings format http://www.cs.au.dk/~jakobt/libwkhtmltox_0.10.0_doc/pagesettings.html
}
Here is the main logic of setting the header and footer URL:
var objectSettings = new PdfObjectSettings();
objectSettings.Header.HtmlUrl = headerHtmlUrl;
objectSettings.Header.Spacing = ConfigurationManager.AppSettings["ContentSpacing"];
objectSettings.Footer.HtmlUrl = footerHtmlUrl;
I hope this helps.
Rafi

Using restsharp in c# to consume last.fm services

I'm trying to connect to the last.fm rest services using restsharp. I can deserialize the simple data found at the example: http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=xxxxxxxxxxxxxxxxxxxxxxx
however, when i reach the images section for the artist:
<artist>
<name>Cher</name>
<mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid>
<url>http://www.last.fm/music/Cher</url>
<image size="small">http://userserve-ak.last.fm/serve/34/48511693.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/48511693.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/48511693.png</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/48511693.png</image>
<image size="mega">http://userserve-ak.last.fm/serve/500/48511693/Cher+Tess.png</image>
i am struggling to get the library to map the data. Here is the code I have so far:
namespace *******.Core.LastFm
{
using System.Xml.Serialization;
using System.Collections.Generic;
using System;
public class image
{
[XmlAttribute]
public string Size { get; set; }
public string Value { get; set; }
}
public class ArtistImageCollection : List<image> { }
public class Artist
{
public string Name { get; set; }
public string Mbid { get; set; }
public string Url { get; set; }
[XmlArray]
public ArtistImageCollection Image;
}
}
this doesnt work. does anyone know how to bind this?
[i updated it to reflect nics suggestion - this doesn't work still]
i got the basis for this code from: http://www.aaronstannard.com/post/2010/06/14/How-to-Parse-a-Users-Delicious-Feed-with-RestSharp.aspx
w://
there was no get/set on Image
doh
Dont you need to annotate the Size with [Attribute] and Image with [XmlArray] or something weird like that?