Background image Windows Phone 7 - windows-phone-7

I have a little question, I want to change the background of my application with C#.
I tried this code :
var app = Application.Current as App;
var imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri(imageName, UriKind.Relative))
};
app.RootFrame.Background = imageBrush;
But it doesn't work, the background is dark.. I tried to do :
app.RootFrame.Background = new SolidColorBrush(Colors.Blue);
And it works well. So I don't understand where is the problem, my image is 480*800 px and I set Build Action to Content and Copy to Output Directory to Copy if newer .
Thanks for all

maybe you can try it
var app = Application.Current as App;
if (app == null)
return;
var imageBrush = new ImageBrush
{
};
var uu = new BitmapImage(new Uri(imageName, UriKind.Relative));
uu.CreateOptions = BitmapCreateOptions.None;
imageBrush.ImageSource = uu;
app.RootFrame.Background = imageBrush;
Mark: uu.CreateOptions = BitmapCreateOptions.None;

I'm doing almost the exact same thing successfully with an image, except I'm setting the image as the background to a panorama control. I know someone else had the same problem you did in this post so I suggested setting the background of the LayoutRoot or other control instead of the app.RootFrame.

Thank you both !!
I had previously tried the two solutions separately and it didn't work. But together it works perfectly!
The code :
var imageBrush = new ImageBrush
{
};
var uu = new BitmapImage(new Uri("/Images/image.png", UriKind.Relative));
uu.CreateOptions = BitmapCreateOptions.None;
imageBrush.ImageSource = uu;
LayoutRoot.Background = imageBrush;

Related

Can I add a tap.SetBinding using Xamarin's new C# markup?

Here's what I am currently doing in C#:
TapGestureRecognizer tap = new TapGestureRecognizer()
{
NumberOfTapsRequired = 1
};
tap.SetBinding(TapGestureRecognizer.CommandProperty, new Binding("DeckTapCommandAsync", source: GD));
tap.SetBinding(TapGestureRecognizer.CommandParameterProperty, new Binding("TapCommandParam", source: GD));
GestureRecognizers.Add(tap);
What I would like to know is if there is any way I can do this using Xamarin.Forms C# markup
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/csharp-markup
Yes, you could use SetBinding for TapGestureRecognizer.
Using ICommand:
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.SetBinding (TapGestureRecognizer.CommandProperty, "TapCommand");
image.GestureRecognizers.Add(tapGestureRecognizer);
For more details, you could check the link: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/tap#using-icommand
You could download the source file from the link: https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/workingwithgestures-tapgesture/
Or you could set with below:
// Image TRASH
TapGestureRecognizer tgrTrash = new TapGestureRecognizer();
tgrTrash.SetBinding(TapGestureRecognizer.CommandProperty, new Binding("BindingContext.TrashCommand", source: this));
tgrTrash.SetBinding(TapGestureRecognizer.CommandParameterProperty, ".");
Image imageTrash = new Image() { Source = "trash.png" };
//Label lTrash = new Label { Text = "Trash", VerticalTextAlignment = TextAlignment.Center };
imageTrash.GestureRecognizers.Add(tgrTrash);
You could download the source file from the link: https://github.com/WendyZang/TestBindingWithListView

Load CCSprite Image from URL - CocosSharp + Xamarin.forms

I am working on Xamarin.Forms + CocosSharp Application. Here I want to load an image from an URL in cocoassharp using CCSprite. How can I achieve this? Normal CCSprite image is created like: var sprite = new CCSprite("image.png");
It is better to use async for stream and Read. I just did testing in place where that was not convenient but you should use async versions.
var webClient = new HttpClient();
var imageStream = webClient.GetStreamAsync(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png")).Result;
byte[] imageBytes = new byte[imageStream.Length];
int read=0;
do
{
read += imageStream.Read(imageBytes, read, imageBytes.Length- read);
} while (read< imageBytes.Length);
CCTexture2D texture = new CCTexture2D(imageBytes);
var sprite = new CCSprite(texture);

UWP - Why is my simple animation not running

I am totally lost at the moment. What is wrong with my animation? Why is it not running? Any help would be highly appreciated! I want to develop sort of an circular progress bar which is "rolling in" as if the bar was filled up.
The following code runs inside an empty UWP app in the MainPage's Loaded Handler. Nothing else...
ArcSegment myArcSegment = new ArcSegment();
myArcSegment.Size = new Size(90, 80);
myArcSegment.SweepDirection = SweepDirection.Clockwise;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myArcSegment);
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(100, 200);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
Path myPath = new Path();
myPath.Stroke = new SolidColorBrush(Colors.Aqua);
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
PointAnimation mySizeAnimation = new PointAnimation();
mySizeAnimation.Duration = TimeSpan.FromSeconds(2);
mySizeAnimation.From = new Point(90, 80);
mySizeAnimation.To = new Point(500, 200);
Storyboard.SetTarget(mySizeAnimation, myArcSegment);
Storyboard.SetTargetProperty(mySizeAnimation, nameof(ArcSegment.Point));
Storyboard ellipseStoryboard = new Storyboard();
ellipseStoryboard.Children.Add(mySizeAnimation);
myPath.Loaded += delegate (object o, RoutedEventArgs e)
{
ellipseStoryboard.Begin();
};
Canvas containerCanvas = new Canvas();
containerCanvas.Children.Add(myPath);
Content = containerCanvas;
Thank you for your help!
Oh my... I just read this post: http://blog.jerrynixon.com/2012/06/windows-8-animated-pie-slice.html
By accident I read about the EnableDependendAnimation Property... never heared of it, but Setting it to true just made the Animation run. I will read up on that now. Thanks anyways!

removeAllChildren is not working in createjs

I'm trying to change the bitmap image in createjs and want to remove all children in a container when reset button is clicked. But removeAllChildren is not working in me.
function drawPhoneImage() {
stage = new createjs.Stage('canvas');
container = new createjs.Container();
phone = new createjs.Bitmap(phoneImg);
phone.x = 268;
phone.y = 64;
stage.addChild(container);
container.addChild(phone);
stage.update();
phone.addEventListener("click", function() {
console.log('phone clicked');
createjs.Ticker.addEventListener("tick", movePhoneImage);
});
}
function movePhoneImage(event) {
phone.x -=10;
if(phone.x < 156) {
phone.x =156;
showPhoneSnap();
}
stage.update(event);
}
Then after clicking the phone object, I'll need to replace it with another bitmap(which works):
function showPhoneSnap() {
snap = new createjs.Bitmap(snapImg);
snap.x = 156;
snap.y = 64;
container.removeAllChildren();
container.addChild(snap);
stage.update();
}
At first, removeAllChildren is working in the first child of the container, but when i tried resetting the stage after adding another bitmap in the container..removeAllChildren() is not working.
function resetStage() {
container.removeAllChildren();
stage.update();
}
I'm having a hard time solving this issue, thanks for anyone who can help.
Make sure that "snapImg" is an image that is loaded.
snap = new createjs.Bitmap(snapImg);
The issue is that you are not updating the stage when the image is loaded.
var image = new Image();
image.src = "path";
image.onload = showPhoneSnap;
function showPhoneSnap() {
//This will ensure that the image is ready.
var bmp = new createjs.Bitmap(this);
...
stage.update();
}

how to add tooltip to pushpin on windowsphone

I've been doing a essay about map on windows phone. I added pushpins default into map and its content is a image. I want to show information when I tap or click on pushpin, but I don't know what to do. I've just thought about use tooltip to show info, but I can't do it.
here is my createpushpin function.
can you help me? thank you for all kind of you!
private void CreateNewPushpin(object selectedItem)
{
var pushpinPrototype = selectedItem as Pushpinsmodel;
var pushpinicon = pushpinPrototype.Icon;
Pushpin pushpins = new Pushpin() { Tag = adress.Name };
pushpins.Background = new SolidColorBrush(Colors.Green);
pushpins.Location = new GeoCoordinate(lad, long);
ImageBrush image = new ImageBrush() {
ImageSource = new System.Windows.Media.Imaging.BitmapImage
(pushpinicon)};
Ellipse elip = new Ellipse()
{
Fill = image,
Name = adress.Name,
StrokeThickness = 10,
Height = 30,
Width = 30
};
pushpins.Content = elip;
var tooltipText = new ToolTip { Content = adress.Name};
ToolTipService.SetToolTip(pushpins, tooltipText);
map1.Children.Add(pushpins);
listpushpin.Add(pushpins);
this.map1.SetView(pushpins.Location, 18.0);
}

Resources