I am trying to create a tile using FlipTileData in Windows Phone 8. I use this code:
const string mainPage = "/MainPage.xaml";
...
Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
FlipTileData tileData = new FlipTileData();
tileData.Title = tileTitle;
tileData.BackgroundImage = new Uri("isostore:" + isourl);
tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
ShellTile.Create(mp, tileData);
This throws an InvalidOperationException at the ShellTile.Create method. There are no other tiles with the same Navigation URI. What am I doing wrong here?
This code works fine using the StandardTileData class, excluding the SmallBackgroundImage and WideBackgroundImage properties.
If it matters, the full code is:
const string mainPage = "/MainPage.xaml";
...
private void createbutton_Click(object sender, RoutedEventArgs e)
{
string tileId = new Random().Next().ToString();
Uri mp = new Uri(mainPage + "?" + "tileid=" + tileId, UriKind.Relative);
WriteableBitmap wbmp = new WriteableBitmap(tileGrid, null);
string isourl = "/Shared/ShellContent/" + tileId + ".jpg";
IsolatedStorageFileStream isfs = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(isourl);
wbmp.SaveJpeg(isfs, 173, 173, 0, 100);
isfs.Close();
FlipTileData tileData = new FlipTileData();
tileData.Title = tileTitle;
tileData.BackgroundImage = new Uri("isostore:" + isourl);
tileData.SmallBackgroundImage = new Uri("isostore:" + isourl);
tileData.WideBackgroundImage = new Uri("isostore:" + isourl);
ShellTile.Create(mp, tileData);
}
If using the new tile templates you need to use the overload of ShellTile.Create() that includes a third parameter.
This should do the trick:
ShellTile.Create(mp, tileData, true);
Are you calling this code inside the Closing handler?
In Windows Phone 8, creating a Tile by using the Create(Uri, ShellTileData) method inside the Closing handler will throw an InvalidOperationException.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206947(v=vs.105).aspx
edit: i guess not, since you said it worked with StandardTileData...
Related
I'm trying to change my image source and some text in a textblock, the source comes from a class that is returned from a WCF service and is in a String format, when i use some functions in my code, images and text will update, but if i try to update it right before a Thread.Sleep it won't change, same for the textblock
Here's the problematic code:
//ris is the class returned from the server
image.Source = new BitmapImage(new Uri("Res/" + ris.carta + ".png", UriKind.Relative));
if (ris.IDv == ID)
{
puntiuno += ris.punti;
txtb_info.Text += "\nHai vinto la mano!";
mano.Add(ricevicarte(2)[0]);
V = true;
}
else
{
txtb_info.Text += "\nHai perso la mano!";
puntidue += ris.punti;
mano.Add(ricevicarte(2)[0]);
V = false;
}
//Secondacarta(ris.carta);
System.Threading.Thread.Sleep(5000);
aggiornainterfaccia();
txtb_info.Text += "\nNuova mano!";
blocco = 0;
everything that comes after the Thread.Sleep works, every WPF controls update i try before won't work
Here's the "aggiornainterfaccia()" code:
private void aggiornainterfaccia()
{
ris = null;
carta1_img.Source = new BitmapImage(new Uri("Res/" + mano[0] + ".png", UriKind.Relative));
carta2_img.Source = new BitmapImage(new Uri("Res/" + mano[1] + ".png", UriKind.Relative));
carta3_img.Source = new BitmapImage(new Uri("Res/" + mano[2] + ".png", UriKind.Relative));
image.Source = new BitmapImage(new Uri("Res/dorso.png", UriKind.Relative));
txt_punti_p1.Text = "Punti: " + puntiuno.ToString();
txt_punti_p2.Text = "Punti: " + puntidue.ToString();
txtb_info.Text = "";
if (V)
{
lbl_mano.Content = "Sei di mano!";
}
else
{
lbl_mano.Content = "Non sei di mano!";
}
}
this is called right after the delay and it works and its function is to reset the interface to a initial state
Running this code below gives me this unexpected result:
private async void OpenItemAppBarBtn_Click(object sender, RoutedEventArgs e)
{
MediaViewModel media = MyListView.SelectedItem as MediaViewModel;
if (media.VidOrPic)
{
var uriString = "ms-appdata:///local/" + media.Name + ".mp4";
Uri muUri = new Uri(uriString);
Launcher.LaunchUriAsync(new Uri(uriString, UriKind.RelativeOrAbsolute));
}
else
{
var uriString = "ms-appdata:///local/" + media.Name + ".jpeg";
Uri muUri = new Uri(uriString);
Launcher.LaunchUriAsync(new Uri(uriString, UriKind.RelativeOrAbsolute));
}
}
UriString Content:
to run the file use Launcher.LaunchFileAsync, not Launcher.LaunchUriAsync
var uriString = "ms-appdata:///local/" + media.Name + ".mp4";
Uri muUri = new Uri(uriString);
var file = await StorageFile.GetFileFromApplicationUriAsync(muUri);
await Launcher.LaunchFileAsync(file);
The Launcher.LaunchUriAsync method always shows the application picker, if no default application is associated with the Uri you provide.
However, there's an overload:
Launcher.LaunchUriAsync(Uri, LauncherOptions)
The launcher options allow you to set a property called DisplayApplicationPicker. If the default app is defined and you set this value to true, using the overload, the application will start directly, without displaying the application picker.
I am trying to save Barcode Image in database. What my code currently generating is just a long string of URL. My code is mentioned below:
string barCode = ds.Tables[0].Rows[0]["productId"].ToString();
System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80))
{
using (Graphics graphics = Graphics.FromImage(bitMap))
{
// Font oFont = new Font("Free 3 of 9 Extended", 16);
Font oFont = new Font("IDAutomationHC39M", 16);
PointF point = new PointF(2f, 2f);
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush whiteBrush = new SolidBrush(Color.White);
graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
graphics.DrawString("*" + barCode + "*", oFont, blackBrush, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
Convert.ToBase64String(byteImage);
imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
**// I think Problem is here, in these lines //**
lblChkCopyIMAge.Text = imgBarCode.ToString();
}
placehod.Controls.Add(imgBarCode);
}
Can please anyone assist me to save complete Barcode image in specific folder and respective URL in database so that I can use it further. The code written above is just generating barcode image and a long string URL. When I saved it in database it is saving this string in URL: "System.Web.UI.WebControls.Label". I have used nvarchar(max) datatype to save ImageURL.
My code to Save in database is mentioned below:
string strcmd5 = "update product set symbology=" + "'" + "IDAutomationHC39M" + "'" + "," + "barcodeimage=" + "'" + lblChkCopyIMAge + "'" + "where productId=" + int.Parse(Label1.Text);
SqlCommand objsqlcmd5 = new SqlCommand(strcmd5, objsqlcon4);
int h = objsqlcmd5.ExecuteNonQuery();
objsqlcon4.Close();
if (h > 0)
{
Response.Write("Record has submitted Successfully");
ScriptManager.RegisterStartupScript(this, this.GetType(), "barcode", "alert('Saved Successfully');", true);
}
You're setting the value to a label control:
"barcodeimage=" + "'" + lblChkCopyIMAge + "'"
As an object, the default string representation for a label control is the name of the type. You probably want to use its .Text property instead?
"barcodeimage=" + "'" + lblChkCopyIMAge.Text + "'"
Note that you should also really look into using parameterized queries for your database interaction. As it stands right now, any user input used in this query is a SQL injection vulnerability.
Live tile doesn't work after upgrading the project from WP7 to WP8. Does anyone know the reason?
I've done an custom tile, and I'm saving it as a picture in IsolatedStorage.
The code for Tile in Scheduled Agent:
.
.
.
ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
if (tile != null)
{
FlipTileData data = new FlipTileData()
{
SmallBackgroundImage = new Uri("isostore:" + mediumTile, UriKind.RelativeOrAbsolute),
BackgroundImage = new Uri("isostore:" + mediumTile, UriKind.RelativeOrAbsolute),
WideBackgroundImage = new Uri("isostore:" + wideTile, UriKind.RelativeOrAbsolute)
};
tile.Update(data);
}
NotifyComplete();
In order to use an image in your IsolatedStorage, you need to use the /Shared/ShellContent path. Here is your code with the fix:
ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();
if (tile != null)
{
FlipTileData data = new FlipTileData()
{
SmallBackgroundImage = new Uri("isostore:/Shared/ShellContent/" + mediumTile, UriKind.RelativeOrAbsolute),
BackgroundImage = new Uri("isostore:/Shared/ShellContent/" + mediumTile, UriKind.RelativeOrAbsolute),
WideBackgroundImage = new Uri("isostore:/Shared/ShellContent/" + wideTile, UriKind.RelativeOrAbsolute)
};
tile.Update(data);
}
NotifyComplete();
Windows 8 app - metro app - Hi I want update tile image from web but I can not get it to work. I use this Link
I only made some small customization but image from web not working for me. I have image in string src1 , if I use const string src1 = "ms-appx:///Assets/clock24x24.png"; then image working but from web it not working. Does anyone have some idea?
public static void CreateSchedule()
{
var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
var plannedUpdated = tileUpdater.GetScheduledTileNotifications();
DateTime now = DateTime.Now;
DateTime planTill = now.AddHours(4);
const string src1 = "http://cdn.thenextweb.com/wp-content/blogs.dir/1/files/2012/02/Screen-Shot-2012-02-21-at-4.48.56-PM.png";
DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1);
if (plannedUpdated.Count > 0)
updateTime = plannedUpdated.Select(x => x.DeliveryTime.DateTime).Union(new [] { updateTime }).Max();
string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideImageAndText01'>"
+ "<text id='1'>This tile notification uses web images</text>"
+ "<image id='1' src='" + src1 + "' alt='Web image'/>"
+ "</binding>"
+ "<binding template='TileSquareImage'>"
+ "<image id='1' src='" + src1 + "' alt='Web image'/>"
+ "</binding>"
+ "</visual>"
+ "</tile>";
var tileXmlNow = string.Format(xml);
XmlDocument documentNow = new XmlDocument();
documentNow.LoadXml(tileXmlNow);
tileUpdater.Update(new TileNotification(documentNow) { ExpirationTime = now.AddMinutes(1) });
for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddMinutes(1))
{
Debug.WriteLine(startPlanning);
Debug.WriteLine(planTill);
try
{
var tileXml = string.Format(xml);
XmlDocument document = new XmlDocument();
document.LoadXml(tileXml);
ScheduledTileNotification scheduledNotification = new ScheduledTileNotification(document, new DateTimeOffset(startPlanning)) { ExpirationTime = startPlanning.AddMinutes(1) };
tileUpdater.AddToSchedule(scheduledNotification);
}
catch (Exception e)
{
}
}
}
Have you activated the Internet functionality in your package AppxManifest file?