differentiating primary tile vs app-list wp8 - c#

I am developing an app for WP8.I want to know how to find out that my app is coming to foreground by clicking on the App-list or primary tile which user created.In a way I want to know how many users creates primary tile.

You can add a navigation parameter to your secondary tile like this :
string tileParameter = "Param=myParameter";
ShellTile tile = CheckIfTileExist(tileParameter);
if (tile == null)
{
StandardTileData secondaryTile = new StandardTileData
{
Title = tileParameter,
BackgroundImage = new Uri("Background-Secondary.png", UriKind.Relative),
Count = 2,
BackContent = "Secondary Tile Test"
};
ShellTile.Create(new Uri("/MainPage.xaml?" + tileParameter, UriKind.Relative), secondaryTile);
}
and then, in your MainPage's OnNavigatedTo event, you can get this parameter with something like this:
if (this.NavigationContext.QueryString.ContainsKey("Param"))
{
string param = this.NavigationContext.QueryString["Param"];//Get "Param" this query string.
//Do whatever you want with this parameter
}

Do you have a query string in your URI? If so you can check the NavigationContext.QueryString and see if the parameter used from your secondary tile is set or not.

Related

c# setting the name of a dynamically created button so it can be called later

how do i set a buttons name when i created it in c# so i can call it later?
i have a a List of strings (Commands).
i loop over it an create a button for each item in the List.
commands.ForEach(delegate (String i)
{
Button button = new Button()
{
Name = i,
Tag = i,
MaxWidth = 50,
MaxHeight = 50,
BorderBrush = null
};
button.Click += new RoutedEventHandler(button_Click);
this.grid.Children.Add(button);
Uri resourceUri = new Uri("led_Off.png", UriKind.Relative);
StreamResourceInfo streamInfo = Application.GetResourceStream(resourceUri);
BitmapFrame temp = BitmapFrame.Create(streamInfo.Stream);
var brush = new ImageBrush();
brush.ImageSource = temp;
button.Background = brush;
});
This loop works fine until i add the line
Name = i
i am in a spot where these buttons were created and i now need to change some of there back ground images.
is there a better way to call them then by there name?
Name should be a valid string: try Name = "button" + i.ToString() (FYI, Button Name cannot be just "1", it's an invalid Name). Also, Tag =i.ToString(). Hope this may help
Don't do it, use data binding and data templating with commands instead.
There is no reason to ever create any UI elements in a loop in WPF.
Edit: Just this.

Set Adaptive Tile Background from Image

I am creating a TileNotification to display the last edited project on my app's tile. When doing this I want to set the tile's background to be the project cover image. I'm creating the TileContent like this:
TileContent content = new TileContent()
{
Visual = new TileVisual()
{
TileMedium = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
BackgroundImage = new TileBackgroundImage()
{
Source = new TileImageSource("ms-appx:///Assets/Images/MainPageBackground.jpg"),
Overlay = 10
},
Children =
{
new TileText()
{
Text = DataModel.Instance.CurrentProject.Title,
Align = TileTextAlign.Left
}
}
}
}
}
};
The problem is that the only way to set the Source property seems to be with a TileImageSource, which only accepts a string. And since the project's cover image is stored in ApplicationData.Current.LocalFolder... I can't just give it a string. Is there any way to set the image source from an actual image rather than a string?
After some more searching I found this method of doing it.
You can use the "ms-appdata:///Local" prefix to get the file. In my case:
$"ms-appdata:///local/Projects/{ProjectName}/Slides/0.gif".
That can then be handed in as the source.

Change default tile image url

Is there any way I could change the Uris of the default tile images in the WMAppManifest.xml at runtime?
For example I would like to enable an option for users to select the tile image in the settings of my app. This is not the problem because I can then update the main tile with the new image if the app is pinned to the start, but if the app is not pinned and the user wants to pin the app another time then the default image will be used, and this is not the behavior I want, I want the tile to have the image the user selected in the settings. How to achieve this if possible?
I figured it out, I didn't know the ShellTile.ActiveTiles would always contain the default tile, whether the app is pinned or not, so I just updated this tile when the settings item changed:
private async void UpdateTile(bool isTransparent)
{
ShellTile defaultTile = ShellTile.ActiveTiles.FirstOrDefault();
if (defaultTile != null)
{
string tileFolder = isTransparent ? "Transparent" : "Normal";
defaultTile.Update(new FlipTileData()
{
SmallBackgroundImage = new Uri("appdata:/Assets/Tiles/" + tileFolder + "/Logo.scale-100.png"),
BackgroundImage = new Uri("appdata:/Assets/Tiles/" + tileFolder + "/Logo.scale-180.png"),
WideBackgroundImage = new Uri("appdata:/Assets/Tiles/" + tileFolder + "/WideLogo.scale-180.png")
});
}
}

How to go to the Windows Phone Start Screen directly from within my app?

My app has the option to create many secondary tiles. When user try to pin an existing tile, the app asks the user to go to the Start Screen to remove the tile first.
Is there a way programmatically to navigate to the WP Start Screen from my app?
UPDATE
I know user can just click the start button or back button. But I want to detect if that navigation is made to set certain flags. And it would be a little convenient for the user if the apps could help them to navigate automatically.
As you said "When user try to pin an existing tile" means you want to update the existing tile . Use the code for Updating the existing tile.
public static void UpdateAppTile(string navigationUri)
{
var tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(navigationUri));
if (tile != null)
{
var tileData = new FlipTileData
{
SmallBackgroundImage = new Uri("/Assets/Tiles/small.png", UriKind.Relative),
BackgroundImage = new Uri("/Assets/Tiles/medium.png", UriKind.Relative),
WideBackgroundImage = new Uri("/Assets/Tiles/wide.png", UriKind.Relative),
// other properties
};
tile.Update(tileData);
}
}
And for deleting the tile
public static void DeleteAppTile(string navigationUri)
{
var tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(navigationUri));
if (tile != null)
{
tileToFind.Delete();
}
}
From the UX point of view, you should already avoid such situations by disabling (or adding to the tile 'unpin from start' option) for the corresponding tile, if it's already pinned to start.
public static bool CheckIfTileExists(string tileUri)
{
ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(
tile => tile.NavigationUri.ToString().Contains(tileUri));
if (shellTile == null)
return false;
return true;
}

Windows Phone 8 secondary tiles crash when not in Debug Mode

I am testing a basic secondary live tile(ShellTile) functionality with the code below. Creating the tile works fine but using the tile to navigate to the URI always works in debug mode but not when testing disconnected from the computer and I don't know why. I am testing with just 1 tile. Funny thing is, if I restart, secondary tile will work one more time after the restart. What am I missing?
1> This is the code behind that makes the secondary tile
string path = #"/Views/test.xaml?text=" + parameter.ToString();
StandardTileData tileData = new StandardTileData
{
Title = parameter.ToString(),
BackTitle = parameter.ToString(),
BackContent = parameter.ToString()
};
ShellTile.Create(new Uri(path, UriKind.Relative), tileData);
2.test.xaml code
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string text= "";
text= NavigationContext.QueryString["text"];
}
Thanks,
Jamie
When the Tile which NavigationUri is same with your parameter, the ShellTile.Create method will crash. You should check if the tile is exist first, like this:
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(parameter));
You can choose Contains or Equals by your content. and then:
if (TileToFind != null)
{
// Tile is existed, you can update it, but not add the same uri tile
}
else
{
// you can add new tile
}

Categories

Resources