WP7 Popup not showing - windows-phone-7

In my app I want to display a simple string within a popup when the user clicks on an image. For this I added a Tap gesture listener to the image and within the handler I have the following code:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
The call to WriteLine prints in the debugger output window but the popup doesn't get displayed. What am I doing wrong here?
Thanks for your help!

I tried your code and the Popup is displayed. I think the problem for you is the Position for the Image relative to the Mouse. Try to set another Background for the Parent Container and I think you'll see the Popup. You can also try to play around with
Point pos = e.GetPosition(null);
until you get the Position you require

Related

Wear OS Button Background

Button(
onClick = {
raceOn = !raceOn
if (raceOn) {
text.value = "Stop!"
color.value = Color.Red
} else {
text.value = "Go!"
color.value = Color.Green
}
},
modifier = Modifier.background(color = color.value),
content = {
Text(
text = "${text.value}",
)
}
)
Using the code above, I got the attached image. What I want is the inside of the button to be green and not the background behind it. I couldn't the right property to modify.
Has anyone here tried to modify the Button background? Or perhaps suggest another solution. I tried the OutlinedButton and wasn't successful.
Thanks!
Use the MaterialTheme ButtonColors.
val colors: ButtonColors = ButtonDefaults.primaryButtonColors(backgroundColor = Color.Red)
Button(onClick = { /*TODO*/ }, colors = ButtonDefaults.primaryButtonColors()) {
// TODO
}
You can also update via setting the MaterialTheme defaults.
val wearColorPalette: Colors = Colors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200,
secondaryVariant = Teal200,
error = Red400,
onPrimary = Color.Black,
onSecondary = Color.Black,
onError = Color.Black
)
...
MaterialTheme(
colors = wearColorPalette,
typography = Typography,
// For shapes, we generally recommend using the default Material Wear shapes which are
// optimized for round and non-round devices.
content = content
)

ZXing.Mobile - How to change the size of the camera scanner?

UPDATE:
I've tried implementing this in an App.cs method called OpenCameraScanner (you would call this on click of a button on the page from which you want to scan):
App.cs
------------------------------------------------
public static ZXingScannerPage ScanPage;
public static ZXing.Result ScanResult;
public static async void OpenCameraScanner()
{
ScanPage = new ZXingScannerPage(customOverlay: customOverlay);
ScanPage.OnScanResult += (result) =>
{
ScanPage.IsScanning = false;
ScanResult = result;
Device.BeginInvokeOnMainThread(() =>
{
App.CurrentApp.CurrentPage.Navigation.PopModalAsync();
App.CurrentApp.CurrentPage.DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
var scanPage = new NavigationPage(ScanPage);
await App.CurrentApp.CurrentPage.Navigation.PushModalAsync(ScanPage);
}
However, when this method is called, the screen that opens is blank white, and you can't see the camera view behind it. Not sure why?
I'm using ZXing.Mobile in a Xamarin.Forms project (for iOS right now) for camera scanning functionality on an iPad.
Currently, I have it working great with the following 2 lines:
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
However, when the camera is open to scan, it takes up the entire iPad screen, which is really big.
Question: Is there a way to adjust the size of the camera overlay? (so that it's not full screen)
I see that the scanner.Scan() method takes an optional options parameter of type ZXing.Mobile.MobileBarcodeScanningOptions - I tried playing around with that, but the only possible relevant option there is a CameraResolutionSelector - but I'm having a really hard time finding any documentation on that.
There is a ZXing sample app that shows how to embed the ZXingScannerView and ZXingDefaultOverlay into a Xamarin.Form's Grid:
https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/CustomScanPage.cs
public CustomScanPage () : base ()
{
zxing = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingScannerView",
};
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread (async () => {
// Stop analysis until we navigate away so we don't keep reading barcodes
zxing.IsAnalyzing = false;
// Show an alert
await DisplayAlert ("Scanned Barcode", result.Text, "OK");
// Navigate away
await Navigation.PopAsync ();
});
overlay = new ZXingDefaultOverlay
{
TopText = "Hold your phone up to the barcode",
BottomText = "Scanning will happen automatically",
ShowFlashButton = zxing.HasTorch,
AutomationId = "zxingDefaultOverlay",
};
overlay.FlashButtonClicked += (sender, e) => {
zxing.IsTorchOn = !zxing.IsTorchOn;
};
var grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
grid.Children.Add(zxing);
grid.Children.Add(overlay);
// The root page of your application
Content = grid;
}

How to use TextButtonStyle.overFont?

I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.

Pictures keep going to the top left.(Actionscript 3)

So my project was to make two gallery pages. I called them "gallery1" and "gallery2".The gallery pages each have 5 thumbnails that act like buttons so when you click on em, it opens an swf of the picture. Now the problem is, it always opens on the top left, i want them to be in the middle of the page. This is the code for gallery1. Gallery 2 is the samething but with different pics. b1-b5 are the thumbnails.Please help.
var swfRequest1:URLRequest = new URLRequest("image1.swf");
var swfRequest2:URLRequest = new URLRequest("image2.swf");
var swfRequest3:URLRequest = new URLRequest("image3.swf");
var swfRequest4:URLRequest = new URLRequest("image4.swf");
var swfRequest5:URLRequest = new URLRequest("image5.swf");
var swfLoader:Loader = new Loader();
function opengal(evt:MouseEvent):void
{
var pTarget:String = evt.currentTarget.name;
if(pTarget == "b1")
{
swfLoader.load(swfRequest1);
addChild(swfLoader);
}
else if(pTarget == "b2")
{
swfLoader.load(swfRequest2);
addChild(swfLoader);
}
else if(pTarget == "b3")
{
swfLoader.load(swfRequest3);
addChild(swfLoader);
}
else if (pTarget == "b4")
{
swfLoader.load(swfRequest4);
addChild(swfLoader);
}
else if(pTarget == "b5")
{
swfLoader.load(swfRequest5);
addChild(swfLoader);
}
};
b1.addEventListener(MouseEvent.CLICK, opengal);
b2.addEventListener(MouseEvent.CLICK, opengal);
b3.addEventListener(MouseEvent.CLICK, opengal);
b4.addEventListener(MouseEvent.CLICK, opengal);
b5.addEventListener(MouseEvent.CLICK, opengal);
To set your loaded content in the middle of your stage, you can do like this :
// store files path into an array
var files:Array = ['image01.swf', 'image02.swf', 'image03.swf', 'image04.swf', 'image05.swf'];
var loader:Loader = new Loader();
// use loader.contentLoaderInfo to listen to Event.INIT
loader.contentLoaderInfo.addEventListener(
Event.INIT, function(e:Event):void {
// center our loader
loader.x = (stage.stageWidth - loader.width)/2;
loader.y = (stage.stageHeight - loader.height)/2;
})
addChild(loader);
function opengal(evt:MouseEvent):void {
// here the pTarget should be between 0 and 4 as an array index
var pTarget:int = Number((evt.currentTarget.name).substr(-1, 1)) - 1;
loader.load(new URLRequest(files[pTarget]));
};
...
I hope this can help you.
You have to position your swfLoader in the middle of the screen.
You can do this with this code:
swfLoader.x = (swfLoader.width - stage.stageWidth)/2; // and the y axis in a similar way
The required width and height properties can be retrieved when the contentLoaderInfo dispatches an Event.INIT.

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