Windows Phone 7.1 live tile background images not setting - c#

I am trying to change the background images (front and back) of the live tile for a windows phone 7.1 app however the background images are never set. I've added the images to the project and have made sure to specify their names properly in the Uri() constructor. I can't seem to be able to detect the problem. Here's the code.
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
String result = "Default";
String company = "";
String image = "";
//Method That Executes After Every DownloadStringAsync() Call by WebClient
public void wb_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)
{
result = e.Result;
int newCount = 1;
// Application Tile is always the first Tile, even if it is not pinned to Start.
ShellTile TileToFind = ShellTile.ActiveTiles.First();
// Application should always be found
if (TileToFind != null)
{
// Set the properties to update for the Application Tile.
// Empty strings for the text values and URIs will result in the property being cleared.
StandardTileData NewTileData = new StandardTileData
{
Title = "Stocks App",
BackgroundImage = new Uri(image, UriKind.Relative),
Count = newCount,
BackTitle = company,
BackBackgroundImage = new Uri(image, UriKind.Relative), //**The problem is here**
BackContent = result
};
// Update the Application Tile
TileToFind.Update(NewTileData);
}
}
//Method for Radio Button When Google is Selected
private void radioButton1_Checked(object sender, RoutedEventArgs e)
{
company = "Google Stock";
image = "google_icon.png";
WebClient wb = new WebClient();
wb.DownloadStringAsync(new Uri("http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=a"));
wb.DownloadStringCompleted += wb_DownloadStringCompleted;
}
//Method for Radio Button When Yahoo is Selected
private void yahooRadioBtn_Checked(object sender, RoutedEventArgs e)
{
company = "Yahoo Stock";
image = "yahoo_icon.png";
WebClient wb = new WebClient();
wb.DownloadStringAsync(new Uri("http://finance.yahoo.com/d/quotes.csv?s=YHOO&f=a"));
wb.DownloadStringCompleted += wb_DownloadStringCompleted;
}
//Method for Radio Button When Apple is Selected
private void appleRadioBtn_Checked(object sender, RoutedEventArgs e)
{
company = "Apple Stock";
image = "apple_icon.png";
WebClient wb = new WebClient();
wb.DownloadStringAsync(new Uri("http://finance.yahoo.com/d/quotes.csv?s=AAPL&f=a"));
wb.DownloadStringCompleted += wb_DownloadStringCompleted;
}
}

Verify that the path of the image and the Build Action is as requested by the documentation
You can find out more at
http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.shell.standardtiledata.backbackgroundimage(v=vs.105).aspx
and
http://msdn.microsoft.com/en-US/library/windowsphone/develop/ff402541(v=vs.105).aspx
Check your files Build Action property is set to Content before any other check

Related

Wikipedia Image list show from wikipedia xml api

I am trying to write a code in which I got as xml format for the first image api from wikipedia. Now I want to parse it through c#. But I cannot get the image while running code. here is my code.
namespace WikiAPIWinForm
{
public partial class WikiForm : Form
{
private const string url1_Image1 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Schloss%20Neuschwanstein%202013.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300"; //show 1st image
private const string url1_Image2 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Neuschwanstein%20castle.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300";// show another image
private const string url1_Image3 = "https://en.wikipedia.org/w/api.php?action=query&titles=File:Hohenschwangau_-_Schloss_Neuschwanstein5.jpg&prop=imageinfo&iiprop=comment|url|dimensions&format=xml&iiurlwidth=300";// show another image
public WikiForm()
{
InitializeComponent();
}
XDocument xmlDocument1 = XDocument.Load(url1_Image1);
XDocument xmlDocument2 = XDocument.Load(url1_Image2);
XDocument xmlDocument3 = XDocument.Load(url1_Image3);
var image1 = (from page in xmlDocument1.Descendants("page")
select new AllImage
{
Title1 = page.Attribute("title").Value,
Imagerepository1 = page.Attribute("imagerepository").Value,
Url1 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages1(image1);
var image2 = (from page in xmlDocument2.Descendants("page")
select new AllImage
{
Title2 = page.Attribute("title").Value,
Imagerepository2 = page.Attribute("imagerepository").Value,
Url2 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages2(image2);
var image3 = (from page in xmlDocument3.Descendants("page")
select new AllImage
{
Title3 = page.Attribute("title").Value,
Imagerepository2 = page.Attribute("imagerepository").Value,
Url3 = page.Element("imageinfo").Element("ii").Attribute("thumburl").Value
});
ShowImages3(image3);
}
private void ShowImages1(IEnumerable<AllImage> image1)
{
var image = image1.First();
pictureLabel1.Text = image.Title1;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.LoadAsync(image.Url1);// asynchronous loading
}
private void ShowImages2(IEnumerable<AllImage> image2)
{
var image = image2.First();
pictureLabel2.Text = image.Title2;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox2.LoadAsync(image.Url2);// asynchronous loading
}
private void ShowImages3(IEnumerable<AllImage> image3)
{
var image = image3.First();
pictureLabel3.Text = image.Title3;
pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox3.LoadAsync(image.Url3);// asynchronous loading
}
}
You need something like
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false; // to prevent a new download until you have finished the old one
XDocument xmlDocument = XDocument.Load(url1_Image);
var images = (from page in xmlDocument.Descendants("page")
select new AllImage
{
Title = page.Attribute("title").Value,
Imagerepository = page.Attribute("imagerepository").Value,
Url = page.Element("imageinfo").Element("ii").Attribute("url").Value
});
ShowImages(images);
};
private void ShowImages(IEnumerable<AllImage> images)
{
var image = images.First();
label1.Text = image.Title;
pictureBox1.LoadAsync(image.Url); // asynchronous loading
}
After downloading the image you need to make the button available.
void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
button1.Enabled = true;
}
We strongly recommend to give normal names to the controls. For example, buttonLoad, labelTitle, pictureBoxWikiImage.
In addition, I see in XML information about only one image. So, for what the IEnumerable collection?

Could not call the secondary tile page to show correctly

Purpose
I want to use secondary tile in my application that can pin the page to the start menu, and when the user click it show the page correctly.
Problem
The page that the user trying to pin to the start up menu contains the information needed to receive from the previous page; therefore, if the page is pinned to the start up menu, and is navigated directly to it, it will not receive all neccessary information to show on the page.
To store the information sent from page to page, I use PhoneApplicationService.Current.State to store the data that need to send to the next page. That data is the selected item from listbox.
My Sample Code
Here is the code that is to select item from the listbox to store, and sent to the next page
Product List.xaml.cs
namespace App_Skin_Test_Final_.All_Files.Product_Files
{
public partial class Product_List : PhoneApplicationPage
{
string pro_list_id;
public Product_List()
{
InitializeComponent();
// ===================================== Add Search application bar =====================================
// Show application bar
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = true;
// Search Application bar
ApplicationBarIconButton btnSearch = new ApplicationBarIconButton();
btnSearch.IconUri = new Uri("/images/Icon Application Bars/Search.png", UriKind.Relative);
btnSearch.Text = "Search";
ApplicationBar.Buttons.Add(btnSearch);
btnSearch.Click += btnSearch_Click;
}
// function Search application bar
private void btnSearch_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/All Files/Product Files/Search.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationContext.QueryString.TryGetValue("pro_list_id", out pro_list_id))
{
}
}
private void lst_product_Loaded(object sender, RoutedEventArgs e)
{
//MessageBox.Show(pro_cate_id);
XDocument data = XDocument.Load("All Files/Database XML/ProductsDry.xml");
var productListData = from q in data.Descendants("DryCategory")
from itemDry in q.Elements("ItemDry") // mean: itemDry in in DryCategory
where q.Attribute("DryCategoryId").Value == pro_list_id
select new ProductsDry
{
ItemDryName = itemDry.Attribute("ItemDryName").Value,
ItemDryImage = getImage(itemDry.Attribute("ItemDryImage").Value),
ItemDryId = itemDry.Attribute("ItemDryId").Value,
ItemDryIngredients = itemDry.Attribute("ItemDryIngredients").Value,
ItemDryDesc1 = itemDry.Attribute("ItemDryDesc1").Value,
ItemDryDesc2 = itemDry.Attribute("ItemDryDesc2").Value,
ItemDryUse = itemDry.Attribute("ItemDryUse").Value
// ItemDryLink=itemDry.Attribute("ItemDryLink").Value
};
lst_product.ItemsSource = productListData;
// NavigationService.GoBack();
}
private System.Windows.Media.ImageSource getImage(string p)
{
return new BitmapImage(new Uri(p, UriKind.Relative));
}
private void lst_product_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (lst_product.SelectedItem != null)
{
PhoneApplicationService.Current.State["myimage"] = (lst_product.SelectedItem as ProductsDry).ItemDryImage;
PhoneApplicationService.Current.State["ItemDryIngridient"] = (lst_product.SelectedItem as ProductsDry).ItemDryIngredients;
PhoneApplicationService.Current.State["ItemDryUse"] = (lst_product.SelectedItem as ProductsDry).ItemDryUse;
PhoneApplicationService.Current.State["ItemDryDesc1"] = (lst_product.SelectedItem as ProductsDry).ItemDryDesc1;
PhoneApplicationService.Current.State["ItemDryDesc2"] = (lst_product.SelectedItem as ProductsDry).ItemDryDesc2;
PhoneApplicationService.Current.State["ItemDryUse"] = (lst_product.SelectedItem as ProductsDry).ItemDryUse;
NavigationService.Navigate(new Uri("/All Files/Product Files/Dry/Product Detail.xaml?&pro_name=" + (lst_product.SelectedItem as ProductsDry).ItemDryName + "&pro_image=" + (lst_product.SelectedItem as ProductsDry).ItemDryImage, UriKind.Relative));
}
else return;
}
private void btnGoBack_Click(object sender, RoutedEventArgs e)
{
if (this.NavigationService.CanGoBack)
{
this.NavigationService.GoBack();
}
}
}
}
And here is the page to receive selected item information from the previouse page "Product List.xaml" and it is the page that I want user to pin specific product that they have selected.
Product Detail.xaml.cs
namespace App_Skin_Test_Final_.All_Files.Product_Files
{
public partial class Product_Detail : PhoneApplicationPage
{
string pro_name;
string pro_image;
string pro_ingridient;
//string pro_link;
string pro_use;
string pro_dryDesc1;
string pro_dryDesc2;
// ImageSource image;
private readonly string SecondaryTileUriSource = "Source=SecondaryTile";
public Product_Detail()
{
InitializeComponent();
// ===================================== Add Search application bar =====================================
// Show application bar
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBar.IsMenuEnabled = true;
// Search Application bar
ApplicationBarIconButton btnSearch = new ApplicationBarIconButton();
btnSearch.IconUri = new Uri("/images/Icon Application Bars/Search.png", UriKind.Relative);
btnSearch.Text = "Search";
ApplicationBar.Buttons.Add(btnSearch);
btnSearch.Click += btnSearch_Click;
ApplicationBarIconButton btnPin = new ApplicationBarIconButton();
btnPin.IconUri = new Uri("/images/Icon Application Bars/pin.png", UriKind.Relative);
btnPin.Text = "Pin";
ApplicationBar.Buttons.Add(btnPin);
btnPin.Click += btnPin_Click;
}
void btnPin_Click(object sender, EventArgs e)
{
// secondary tile can be created only as the result
// of user input in an application
ShellTile tile = this.FindTile(SecondaryTileUriSource);
if(tile==null)
{
//because the UI will navigate to Start
//When a new secondary tile is created
//only one secondary tile can be created at a time
StandardTileData tileData = this.GetSecondaryTileData();
MessageBox.Show("The SecondaryTileUriSource is " + SecondaryTileUriSource);
//having a unique NavigationUri is necessary for distinguishing this tile
string tileUri = string.Concat("/All Files/Product Files/Dry/Product Detail.xmal?", SecondaryTileUriSource);
// MessageBox.Show("the uri is " + tileUri);
ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData);
// ShellTile.Create(new Uri("/All Files/Product Files/Dry/Product Detail.xaml", UriKind.Relative), tileData);
}
}
// function Search application bar
private void btnSearch_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/All Files/Product Files/Search.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Check if the Secondar tile exists
ShellTile secondaryTile = this.FindTile(SecondaryTileUriSource);
if (secondaryTile != null)
{
// ***************************************************** tile.Delete();
MessageBox.Show("Secondary tile exist.");
}
if (NavigationContext.QueryString.TryGetValue("pro_name", out pro_name))
{
}
if (NavigationContext.QueryString.TryGetValue("pro_image", out pro_image))
{
}
txtbPro_Name.Text = pro_name;
BitmapImage bm = PhoneApplicationService.Current.State["myimage"] as BitmapImage;
img_Product.Source = bm;
// Ingridient Text
pro_ingridient = PhoneApplicationService.Current.State["ItemDryIngridient"] as string;
txtb_ingridient.Text = pro_ingridient;
// Find on Somaly store
//pro_link = PhoneApplicationService.Current.State["ItemDryLink"] as String;
//txtb_link = pro_link;
// How to use product
pro_use = PhoneApplicationService.Current.State["ItemDryUse"] as string;
txtb_howToUse.Text = pro_use;
// Description 1 and Description 2
pro_dryDesc1 = PhoneApplicationService.Current.State["ItemDryDesc1"] as string;
txtb_description1.Text = pro_dryDesc1;
pro_dryDesc2 = PhoneApplicationService.Current.State["ItemDryDesc2"] as string;
txtb_description2.Text = pro_dryDesc2;
// txtb_ingridient.Text = pro_image;
// image = getImage(pro_image);
// MessageBox.Show(image);
// img_Product.Source = image;
}
private ImageSource getImage(string img)
{
return new BitmapImage(new Uri(img, UriKind.Relative));
}
/*********************************************
* Create a Secondary Tile for pin application
*********************************************/
private StandardTileData GetSecondaryTileData()
{
StandardTileData titleData = new StandardTileData
{
Title = "Secondary Tile",
BackBackgroundImage = new Uri("/Images/Allures/Base/aba001.jpg", UriKind.Relative),
Count = 5,
BackTitle = "Secondary Tile",
BackgroundImage = new Uri("", UriKind.Relative),
BackContent = "WPG Add Remove Tile Sample"
};
return titleData;
}
private ShellTile FindTile(string partOfUri)
{
ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(
title => title.NavigationUri.ToString().Contains(partOfUri));
return shellTile;
}
}
}
When the user presses on pin application bar button on the Product Detail.xaml page, the page is pinned to the start up menu as normal; however, when they press on pinned page at the start up menu, it never navigate back to the Product Detail page. But if I comment out every line of PhoneApplicationService.Current.State in product detail.xaml.cs, it could navigate to the page but it does not show anything on the page, the information on the selected item.
How can I correct this error to show the page that the user pin to the start as normal?
Kindly help. Thanks
The direct issue is that when launching the app from the secondary tile, the values in the PhoneApplicationService.Current.State dictionary are not populated, so you cannot read them.
But even if you get around that and find out why the state is not populated, I see a bigger problem in the code. I imagine that you show a list of products, and can navigate to the details of each product, and want to allow the user to pin a specific product to the Start page. So, imagine that you store the selected product in the phone state dictionary and then pin the details. The you open the application and select another product - so it will be now stored in the app state, and tapping the pinned tile will open the second product details ...
My suggestion is to redesign the interaction between the pages - if you have some unique id that can identify the products, pass that id to the product detail page, and also store that same id in the uri of the secondary tile, like this:
new Uri("/All Files/Product Files/Dry/Product Detail.xaml?&item_id=" + itemId)
Then, in the OnNavigated() method of the product details page, read the id from the query string, then access the full list of products, locate the product with that id, and display it.
This way all navigations - from secondary tile, resuming the application, etc. will work correctly.

Loading Image into Picturebox from URL

I'm programming an algorithm in C# to download an image from a website and my software automatically fills all the required fields and presses the download button. The problem is that I'm not able to load the image. The dialog box to download image on Internet Explorer is appearing, so I need to get the url of the picture after clicking the button "generate" and load it into the picture box. My code:
private void simpleButton6_Click(object sender, EventArgs e)
{
string i = "0";
HtmlElement hu = webBrowser3.Document.GetElementById("data-text");
hu.Focus();
hu.SetAttribute("Value", txtEncodeData.Text);
HtmlElement hu1 = webBrowser3.Document.GetElementById("color");
hu1.Focus();
Color c = customColorBlender1.SelectedColor;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
hu1.SetAttribute("Value", hex);
HtmlElement hu2 = webBrowser3.Document.GetElementById("effect");
hu2.Focus();
if (comboBoxEdit1.SelectedIndex == 1)
{
i = "1";
}
hu2.SetAttribute("Value", i);
webBrowser3.Document.GetElementById("generate").InvokeMember("click");
t.Interval = 1000;
t.Start();
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
String url = Convert.ToString(webBrowser3.Document.GetElementById("download").InvokeMember("click"));
MessageBox.Show(url);
pictureBox15.ImageLocation = Convert.ToString((Uri)webBrowser3.Document.GetElementById("download").InvokeMember("click"));
}

Where to put label message and only display it after a process is done?

I am a beginner. How and where should i put a label messages after a video is created from below code.
I want to display two messages after the process is completed which is label1: video was created successfully and 2nd messages is videopath of the video.
I only want to display it after the process is completed(video was created).
namespace test
{
public partial class liveRecording : System.Web.UI.Page
{
//video codec
AVIWriter writer = new AVIWriter("MSVC");
protected void Page_Load(object sender, EventArgs e)
{
string streamingSource = "http://xxx.sample.com:85/snapshot.cgi";
string login = "login";
string password = "password";
JPEGStream JPEGSource = new JPEGStream(streamingSource);
JPEGSource.Login = login;
JPEGSource.Password = password;
JPEGSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
JPEGSource.Start();
}
public bool IsRecording = false;
int width = 0;
int height = 0;
Queue<Bitmap> frames = new Queue<Bitmap>(); //Queue that store frames to be written by the recorder thread
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) //event handler for NewFrame
{
//get frame from JPEGStream source
//Bitmap image = eventArgs.Frame;
Bitmap image = (Bitmap)eventArgs.Frame.Clone(); //get a copy of the Bitmap from the source
width = image.Width;
height = image.Height;
if (IsRecording)
{
//enqueue the current frame to be encoded to a video file
frames.Enqueue((Bitmap)image.Clone());
}
if (!IsRecording)
{
IsRecording = true;
Thread th = new Thread(DoRecording);
th.Start();
}
}
private void DoRecording()
{
//writer.FrameRate = 5;
string SavingPath = (Server.MapPath("~\\video\\"));
string VideoName = "ICS_" + String.Format("{0:yyyyMMdd_hhmmss}", DateTime.Now) + ".avi";
writer.Open(SavingPath + VideoName, width, height);
DateTime start = DateTime.Now;
while (DateTime.Now.Subtract(start).Seconds < 30)
{
if (frames.Count > 0)
{
Bitmap bmp = frames.Dequeue();
writer.AddFrame(bmp);//add frames to AVI file
}
}
writer.Close();//close
}
}
}
I only want to display it after the process is completed(video was created).
Then you should use AJAX, basically. Your "start encoding" (or whatever) request should complete quickly, so the user gets an appropriate page back. That page should contain Javascript to regularly poll the server to see whether the task has completed - you'll need some coordination (e.g. via a randomly generated "job ID" which is provided to the client). You could use something like SignalR for "long polling" (where the AJAX fires a request which is expected to wait until either the job has completed or it times out) or just make a quick polling request every few seconds.
I'm afraid none of this is easy if you're new to web development - but the task you're trying to perform isn't easy, in a world based on HTTP requests and responses.

Clear history webbrowser in window phone 7?

In my application, i use webbrowser control.
#region show adve....
public void ShowAd(string link)
{
linkFromservices = "http://ads.diadiem.com/www/delivery/afr.php?refresh=10&zoneid=66&...=";
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(linkFromservices, UriKind.RelativeOrAbsolute));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
result = string.Empty;
try
{
result = e.Result;
if (!string.IsNullOrEmpty(result))
{
result = AddScripttoHTML(result);
webBrowser.NavigateToString(result);
}
}
catch (Exception ex) { }
finally
{
result = string.Empty;
client.DownloadStringCompleted -= new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
}
#endregion
in this link "http://ads.diadiem.com/www/delivery/afr.php?refresh=10&zoneid=66&..." you can see refesh=10 . Every 10 seconds the browser will automatically refresh and change the current advertising alone by random.....
but refresh the memory increased from 200KB to 400KB.
how to release or clear History webbrowser in window phone 7 ?
Thank you all ! please help me.......
The webbrowser controle for WP7 is unable to clear history, you need to create your own webbrowser :
http://franciscojf.wordpress.com/2011/03/27/full-web-browser-control-for-windows-phone-7/

Categories