Is it possible to pin elements from an app to the Tiles page ? as in, the user can create a list in my app, and i would like to allow the user to pin elements from that list to the main tile page, is that possible ?
Thanks
For creating secondary tiles, you need to use the ShellTile.Create method.
Sample code:
string page = "/MainPage.xaml?id=" + itemId;
StandardTileData tileInfo = new StandardTileData
{
BackgroundImage = new Uri("ApplicationTile.png", UriKind.Relative),
Title = "Your tile title"
};
ShellTile.Create(new Uri(page, UriKind.Relative), tileInfo);
That will create a Tile with the specified item id.
Then, to get the item id when the user launches the app, check the NavigationContext.QueryString property.
Here is a tutorial: http://dotnet.dzone.com/articles/using-secondary-shell-tiles
Related
I want to be able to pin page from where the user has navigated to, I want to make its content shows dynamically depending on which item the user has selected to pin. The first secondary tile, I could do it, but the problem is that when there are more than one secondary tile at the start menu, all the secondary tiles are link to the page but the content of the page is all the same as the last secondary tile.
Here is what I do:
From where the page is navigated to, I receive the information and set it display on the page like this:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (!IsolatedStorageSettings.ApplicationSettings.Contains("isolated_image"))
{
IsolatedStorageSettings.ApplicationSettings.Add("isolated_image", NavigationContext.QueryString["pro_image"] as string);
}
![enter image description here][1]
imageBase = (IsolatedStorageSettings.ApplicationSettings["isolated_image"] as string);
StreamResourceInfo sri = null;
Uri uri = new Uri(imageBase, UriKind.Relative);
uriString = uri.ToString();
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
base64 = ((App)Application.Current).ImageToBase64(bitmap);
item_image.Source = ((App)Application.Current).ImageFromBase64(base64);
if (!(IsolatedStorageSettings.ApplicationSettings.Contains("item_name")))
{
IsolatedStorageSettings.ApplicationSettings.Add("item_name", PhoneApplicationService.Current.State["pro_name"]);
}
ShellTile secondaryTile = this.FindTile(SecondaryTileUriSource);
if (secondaryTile != null)
{
item_image.Source = ((App)Application.Current).ImageFromBase64(base64);
}
txtb_product_name.Text = PhoneApplicationService.Current.State["pro_name"] as string;
}
From information I got, when the user press on pin app bar, I create the secondary tile with the unique uri based on "?image_item="+imageBase
void btnPin_Click(object sender, EventArgs e)
{
ShellTile tile = this.FindTile(SecondaryTileUriSource);
if(tile==null)
{
StandardTileData tileData = this.GetSecondaryTileData();
Uri uri = new Uri("/All Files/Product Files/Dry/Product Detail.xaml?item_image=" + imageBase, UriKind.Relative);
MessageBox.Show("the link uri is "+ uri.ToString());
ShellTile.Create(uri, tileData);
}
}
At the end, when I have have multiple secondary tiles at the start menu, the first, and the second secondary tiles will displays the same content on the page like this last secondary tile that I pinned.
I'm sure that the link uri is already unique; otherwise, I could not create multiple secondary tiles. Can anyone help me what's wrong? Thanks
First, I'd change your pinning logic and instead of creating string from your image data use some sort of ID to identify image... You current approach is unnecessary complicated.
It could be as simple as to have: image1,image2, image3 and so on. Then get id from query string and construct image uri like: new Uri("../image" + id)
If you have successfully created multiple secondary tiles, then each must be unique and your problem probably lies in parsing query strings in your OnNavigatedTo()
This is for iPhone.
I have a button and when it's clicked I want to pop-up another control which covers the whole screen. This screen could have any number of controls. And I can close this screen by clicking on an x in the top right corner or programmatically inside any event on the new screen.
I could probably do this by using a UINavigationController which just brings me to a new screen and has a link back to the previous screen but I would just like to ask if there is another option?
What I am doing is I have a map which shows a users location from a pin. But if the user wants to type in a new location instead of using the pin location then they will click a button, go to a new screen, type in an address and click a "suggested" address from what they type.
Any advice would be appreciated or a link to a code sample would be great
You can't use popover for iPhone, I think that you can use Modal View.
yourButton.TouchUpInside += (object sender, EventArgs e) =>
{
YourController yourController = new YourController();
yourController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
this.PresentViewController(yourController, true, null);
};
And to close you only need to dismiss the modal.
If it's an iPad app you can use UIPopoverController.
// myvc is an instance of the view controller you want to display in the popup
UIPopoverController pop = new UIPopoverController(myvc);
// target is another view that the popover will be "anchored" to
pop.PresentFromRect(target.Bounds, target, UIPopoverArrowDirection.Any, true);
If it's an iPhone app you can't use UIPopoverController. If you just want a small input box with a single button, you can use UIAlertView (this works for iPhone and iPad)
UIAlertView alert = new UIAlertView();
alert.Title = "Title";
alert.AddButton("OK");
alert.Message = "Please Enter a Value.";
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.Clicked += (object s, UIButtonEventArgs ev) => {
// handle click event here
// user input will be in alert.GetTextField(0).Text;
};
alert.Show();
i have a problem when i navigate from a secondary tile into my app. The tile is created and has a navigation uri. Now i have a problem:
On "navigateTo" i test the navigationcontext for a specific string. If the string has the number i call this number. The first problem i have is when i navigate to an other page inside the app (after first click on secondary tile) and then return back to mainpage, it also tries to call the number, because the navigationcontext is the same as when i click the secondary tile.
If i clear the navigationcontext after the first click on secondary tile the navigation works. But if i pause the app and than click the secondary tile again the navigationcontext is empty and so no number is called.
Create of tile
IconicTileData tileData = new IconicTileData
{
Title = App.MainViewModel.SelectedPOI.Name,
SmallIconImage = new Uri("/Assets/Images/feature.phone.png", UriKind.Relative),
WideContent1 = App.MainViewModel.SelectedPOI.Name,
WideContent2 = App.MainViewModel.SelectedPOI.Telefonnumber,
WideContent3 = App.MainViewModel.SelectedPOI.Street
};
if (App.MainViewModel.SelectedPOI.Id == -1)
tileData.BackgroundColor = Helper.GetColorFromHexString("#E46D1D");
else
tileData.BackgroundColor = Helper.GetColorFromHexString("#4FAE32");
string SecondaryTileUriSource = String.Format("Source={0}&ID={1}", TILESTATUS, App.MainViewModel.SelectedPOI.Id);
//check if tile exist
ShellTile tile = Helper.FindTile(SecondaryTileUriSource);
if (tile == null)
{
// having a unique NavigationUri is necessary for distinguishing this tile
string tileUri = string.Concat("/MainPage.xaml?", SecondaryTileUriSource);
ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData, true);
}
OnNavigateTo - MainPage
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string status = String.Empty;
if (NavigationContext.QueryString.TryGetValue("Source", out status))
{
MainPivot.SelectedItem = AlarmPivotItem;
//App.MainViewModel.StartAlarm();
//or
//get the number from source/status...
App.MainViewModel.CallNumber(12345);
//NavigationContext.QueryString.Clear();
}
}
Has anybody an example where e.g. a Number is called from a secondary tile and there are maybe at least 2 pages inside the app?
Any other sugestion where the problem can be?
Thank you
Rather than clearing the navigation context, you can use the NavigationMode property to know whether it's a new navigation to the page (for instance, form the secondary tile) or if the user went back from another page:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
{
if (NavigationContext.QueryString.TryGetValue("Source", out status))
{
MainPivot.SelectedItem = AlarmPivotItem;
//App.MainViewModel.StartAlarm();
//or
//get the number from source/status...
App.MainViewModel.CallNumber(12345);
}
}
}
In my application I am using the MediaPlayer to play a selection of songs, however it would be good to be able to get the songs that are going to be played next and display them to the user, either for information, or so they can jump several songs in the queue.
So how can I get a list of the Songs that are coming up in the MediaPlayer queue?
So that I can have a list of them which can be displayed to the user, in some sort of container, probably a ListBox.
I have tried using MediaPlayerQueue however this operator doesn't seem to have any form of functionality?
Thank you for your time and help.
media player in windows phone 7 displaying next song
MediaPlayer.Queue[n]
will give you the required Song instance
You can try this one. It work for wp8.1 silverlight.
SongModel is my custom class
App.Handler.MediaPlayerQueqeLists = new ObservableCollection<SongModel>();
for (int i = 0; i < MediaPlayer.Queue.Count; i++)
{
App.Handler.MediaPlayerQueqeLists.Add(new SongModel
{
Index = i,
Title = MediaPlayer.Queue[i].Name,
Artist = MediaPlayer.Queue[i].Artist.Name,
StringDuration = (new DateTime(MediaPlayer.Queue[i].Duration.Ticks)).ToString("mm:ss")
});
}
llsPlaylist.ItemsSource = App.Handler.MediaPlayerQueqeLists;
I am developing a c# desktop application.
We need to unpin our application tile based on number of conditions. this could happen anytime during the application life-cycle, and not only during installation.
I saw this question on how to unpin a tile in CPP. I tried to do that also in C# with no success.
any help?
Update:
I was able to write a C# code that sets the AppUserModel_StartPinOption to APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL but it didn't help :(
this is the code:
private static void InstallShortcut(string linkPath)
{
// Find the path to the current executable
// String exePath = Process.GetCurrentProcess().MainModule.FileName; //Path to the current exe file that is running. C:\\...
IShellLinkW newShortcut = (IShellLinkW)new CShellLink();
// Create a shortcut to the exe
ErrorHelper.VerifySucceeded(newShortcut.SetPath(targetPath));
ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));
// Open the shortcut property store, set the AppUserModelId property
IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;
var APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL = new PropVariant(0);
var StartPinOption = new PropertyKey(new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}"), 12);
ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(StartPinOption, APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL));
ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
// Commit the shortcut to disk
IPersistFile newShortcutSave = (IPersistFile)newShortcut;
ErrorHelper.VerifySucceeded(newShortcutSave.Save(linkPath, true));
}
I tried both: removing the tile and then recreating it, and changing the params of an existing tile, but nothing worked, the tile stays pinned to the start menu.
Are you talking about your main application tile or a secondary tile? If you are referring to a secondary tile, there is sample code for unpinning in this article. The meat of it is (and I'm modifying a bit for simplicity; see the article for the full code):
// Check to see if this restaurant exists as a secondary tile and then unpin it
string restaurantKey = this.m_ViewModel.Restaurant.Key;
Button button = sender as Button;
if (button != null)
{
if (Windows.UI.StartScreen.SecondaryTile.Exists(restaurantKey))
{
SecondaryTile secondaryTile = new SecondaryTile(restaurantKey);
bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);
if (!isUnpinned)
{
// Do error handling here
}
}
else
{
// If we ever get to this point, something went wrong or the user manually
// removed the tile from their Start screen.
Debug.WriteLine(restaurantKey + " is not currently pinned.");
}
}
According to the MSDN article: System.AppUserModel.StartPinOption (Windows), the No pin install option should be (1)
var APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL = new PropVariant(1);
I got it working by doing this.