Windows 8 - How To Change Live Tile Background Image? - c#

How do I change the background image of a live tile in my Windows 8 app to a local image? The XML for the template I am using is:
<tile>
<visual>
<binding template="TileWideImageAndText01">
<image id="1" src="image1.png" alt="alt text"/>
<text id="1">Text Field 1</text>
</binding>
</visual>
</tile>
For the text, I use
XmlDocument xmltile= Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(Windows.UI.Notifications.TileTemplateType.TileWideImageAndText01);
xmltile.GetElementsByTagName("text")[0].AppendChild(xmltile.CreateTextNode("73°F, Mostly Cloudy"));
TileNotification tileupdate = new Windows.UI.Notifications.TileNotification(xmltile);
Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileupdate);
But what about for the image?

From here:
The following code uses a local image from the app's package. This
type of image is included in your Visual Studio solution file and is
packaged as part of your app. These images are accessed by using the
"ms-appx:///" prefix. As a best practice, we also assign optional alt
text for accessibility purposes such as screen readers.
XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///images/redWide.png");
((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");

Related

Hello! I dont understand how is right use word "component" in sourse Images (WPF) and I have problem with this item

When I write the source of the image in my application (WPF) in the XAML file I have a problem with the path. In this way:
pack://application:,,,/Registration_and_Login_Forms/Images/key-icon.png
I do not have a problem, but I need to use this:
pack://application:,,,/Registration_and_Login_Forms;component/Images/key-icon.png
because without it I have problem with <customcontrols> tags in another xaml file. And if I paste the component I get the error that "could not load file or assembly".
I tried using another way to get a strong path like writing pack://application: + I writing the full path to the image + and pasting the word "component" to different places in this way and etc.
<PasswordBox.Background>
<ImageBrush ImageSource="pack://application:,,,/Registration_and_Login_Forms;component/Images/key-icon.png"
Stretch="None"
AlignmentX="Left"/>
</PasswordBox.Background>
<customcontrols:BindablePasswordBox Password="{Binding Password}"
Height="28"
Margin="0,5,0,0">
</customcontrols:BindablePasswordBox>

where to put images for xamarin forms application

I am developing an application for Android, iOS and Visual Studio using Xamarin
I added the following lines in xaml to use images:
<Image Source="header.png" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
<Button x:Name="Object_Detection" Image="header.png" />
The first is for displaying an image in the header and the second is for displaying a button icon. They link for the same image "header.png"
I put the image under:
- Mobile.Droid\Resources\drawable
- Mobile.iOS\Resources
-Mobile.Windows\Assets
But the image is not shown at all in the Windows 8.1 app.
the image size is 690*79.
how to resolve the problem?
You have to place images in the root Project directory for Windows Phone 8, Windows Phone 8.1 and UWP applications.
This guide will help you
http://developer.xamarin.com/guides/xamarin-forms/working-with/images
Try something like this :
<ContentPage.Resources>
<ResourceDictionary>
<OnPlatform x:Key="ImageHeaders"
x:TypeArguments="ImageSource"
iOS="header.png"
Android="header.png"
WinPhone="Assets/header.png" />
</ResourceDictionary>
</ContentPage.Resources>
<Image Source="{StaticResource ImageHeaders}" />
OR
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<OnPlatform.iOS><FileImageSource File="header.png"/></OnPlatform.iOS>
<OnPlatform.Android><FileImageSource File="header.png"/></OnPlatform.Android>
<OnPlatform.WinPhone><FileImageSource File="Assets/header.png"/></OnPlatform.WinPhone>
</OnPlatform>
</Image.Source>
Not tested, but it seems to work well.
Thanks for all your posts,
the solution was to add the image resource to the windows sub-project directly under the root.
The addition should be made using visual studio so that the image will be taken in consideration by the compiler.

WP 8.1 Silverlight : How to update a Line (coordinate change)

I'm working on an OCR project and part of it is finding the outlines of an object. To debug it, I output lines on the screen of the phone (to represent the outlines) with the <Line /> Xaml element. I'm trying to update the Line each time I find a different outline. The lines show the good result on the first "frame" but then don't move anymore. (The thing that I change are their X1,Y1 and X2,Y2 attributes).
For a Line1 element :
XAML of the element :
<Line x:Name="Line1"
Stroke="Yellow" />
C# that changes the coordinates :
Line1.X1 = some_new_value;
Line1.Y1 = some_new_value2;
Line1.X2 = some_new_value3;
Line1.Y2 = some_new_value4;
This is the C# I have tried to update the line :
Line1.InvalidateArrange();
Line1.InvalidateMeasure();
(separatly and together but it doesn't change anything)
What is the good way of doing this? Or perhaps I shouldn't be using <Line /> and there is a better way to do this, in which case what is it?
You could try Binding through a ViewModel or you can call UpdateLayout for the control or the page itself.
this.UpdateLayout();
Or
Line1.UpdateLayout();

WPF background image [duplicate]

In WinForms it is possible to import an image as a resource, and the image would still work when compiled in the /bin/Debug folder.
I can't figure out how to get this working in WPF, when I run the application the image doesn't load, because the image is saved in /Projects/AppName/images/, and the application is compiled into /Projects/AppName/bin/Debug when I run it in Debug mode.
Do I simply need to make a copy of my Images folder and put it where the application is compiled? Or is there another way. Here is my code which displays my image:
<Image Width="300">
<Image.Source>
<BitmapImage DecodePixelWidth="300" UriSource="/images/jamsnaps-dark.png" />
</Image.Source>
</Image>
Create a folder (e.g. images) in your Visual Studio Project.
Add the image file(s) to that folder.
Set their Build Action to Resource (in the Properties window, see second image in this answer).
Then write the UriSource property like you already did:
UriSource="/images/jamsnaps-dark.png"
That URI is effectively a Resource File Pack URI, where the prefix is automatically added by the XAML Parser.
In code behind, you would write
bitmap.UriSource = new Uri("pack://application:,,,/images/jamsnaps-dark.png");
Two options :
1) Go out from bin/Debug and in to your application folder by ../../ and then to your image.
<Image>
<Image.Source>
<BitmapImage UriSource="../../images/jamsnaps-dark.png" />
</Image.Source>
</Image>
2) Compile your images as Content from properties in the context menu on the image file , and then when compiled they would be placed in been debug.
I don't remember if you also need to tell them to copy local also in properties ( i'm not near a computer at the moment so i can't check .
Add the image to your project directory
In the solutions explorer, right click the image and select Include in Project
Build Action should be set to Resource by default.
You can then start to use the image path relative to the root e.g. images/text.jpg if you put it in a folder called images.

wpf how to use jpg from resource in xaml-image?

In my c#/WPF project, I added a jpg to the resources to embed into the exe file.
Now I want to use this jpg in an image tag, something like
<xmlns:prop="clr-namespace:MyProgram.Properties"
<Image Source="{Binding Source={StaticResource prop:LogoJpg}}"
My problem: it does not work. I got no idea, how to use the image. I could use files from the hdd, but I need the image to be embedded in the exe file.
First, add the image to your project, with a Build Action of "Resource" (not EmbeddedResource). For instance, I've added an image called "logo.jpg" to a folder called Images in my main project.
Then, in XAML, you use just use that resource as follows:
<Image Source="Images\logo.jpg" />
You can also use the pack syntax for the source:
<Image Source="pack://siteoforigin:,,,/Images/logo.jpg" />
Hope this helps.

Categories