I have a universal app project for Windows/WP 8.1, and I am attempting to get the Ads to work on both platforms. In the OnApplyTemplate function of my control, I have an #ifdef to dynamically create the AdControl for either Windows or WP. The code works great on Windows, and on WP the ad shows up just fine; but when I click on it, nothing is happening. I have tried replacing the code with a dynamic Button to make sure something else isn't intercepting the clicks, and the Button works just fine. Any ideas?
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var baseGrid = (Grid)GetTemplateChild("_BaseGrid");
var bannerGrid = (Grid)GetTemplateChild("_BannerGrid");
#if WINDOWS_APP
bannerGrid.Height = 450;
// Create the ad
var ad = new Microsoft.Advertising.WinRT.UI.AdControl()
{
ApplicationId = "0b7b7910-f56d-477c-b0e9-3def577b6359",
AdUnitId = "10056707",
Height = 90,
Width = 728,
Visibility = AdVisibility,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
baseGrid.Children.Add(ad);
#else
// Set the margins appropriately for WP
bannerGrid.Margin = new Thickness(0, 55, 0, 50);
/* This works just fine!
var button = new Button()
{
Content = "Try This!",
Height = 50,
Width = 320,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
button.Click += (object sender, RoutedEventArgs args) =>
{
Nova.Utilities.Logger.Info("User tapped on button.");
};
baseGrid.Children.Add(button);*/
// Create the ads
var ad = new Microsoft.Advertising.Mobile.UI.AdControl("f854ae91-1c0e-469c-8387-6c90ef8fa6a2", "11388154", true)
{
Height = 50,
Width = 320,
Visibility = AdVisibility,
IsEnabled = true,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center
};
ad.IsEngagedChanged += (object sender, RoutedEventArgs args) =>
{
Nova.Utilities.Logger.Info("User tapped on Ad.");
};
baseGrid.Children.Add(ad);
#endif
}
So it seems like this may possibly still be a bug in the system:
This is a bug in our system. We are still actively working on a fix
and work out a release plan. But here is a workaround I found. BTW,
this workaround hasn't been fully tested in our team.
https://social.msdn.microsoft.com/Forums/en-US/053fe091-8ffb-4d6f-a5ca-f39cff4af618/ads-not-responding-to-tap-or-click?forum=aiaforwinphone
Per the comments, some digging showed it might be related not setting the current Context to a Frame correctly:
MonoGame people have run into this problem too with the new Microsoft
Advertising SDK for Windows 8.1. They had to make changes to make the
ads work again. Maybe the prime31 June plugin needs a similar update?
I am asking in the prime31 support forums too.
https://monogame.codeplex.com/discussions/467336
Also I have found other peoples released Unity Windows Store 8.1 games
that suffer from the freezing problem after the ad is displayed
sometimes. I guess they didn't notice it. Example: (the first ad
popping up froze the game graphics for me):
http://apps.microsoft.com/windows/e...mulator/04eea1ba-8792-437f-a7c2-faec620da6bf#
Following the links seem to show some success with setting it to a Grid:
Add Width and Height and Background to and also place it
where you want your Ad to appear. If you do not set Width and Height
and give your Grid a background color if floods all the screen.
https://monogame.codeplex.com/discussions/467336
Best answer I can find on this issue, no one seems to have been able to resolve it any other way.
Related
I'm working on a cross platform app with Xamarin.Forms and on the UWP side, I added this code in MainPage.xaml.cs to change the app title bar to match the navigation bar I'm using:
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.BackgroundColor = Colors.LightSlateGray;
titleBar.ForegroundColor = Colors.White;
titleBar.InactiveBackgroundColor = Colors.LightSlateGray;
titleBar.InactiveForegroundColor = Colors.White;
titleBar.ButtonBackgroundColor = Colors.LightSlateGray;
titleBar.ButtonForegroundColor = Colors.White;
titleBar.ButtonInactiveBackgroundColor = Colors.LightSlateGray;
titleBar.ButtonInactiveForegroundColor = Colors.White;
However, the foreground color is black when the app is active:
When the app is inactive, it actually looks correct:
I've actually noticed that the text shows up as white for a fraction of a second before switching to black. Should I be running this code later, or somewhere else? I've tried before and after LoadApplication. Am I missing something, or is there a better way to handle this in Xamarin?
So it seems there may be a bug with setting the foreground color (when active) to exactly white. Perhaps something Xamarin is doing cancels it out. I found that picking a color that is close to white works just fine, such as this:
var titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.BackgroundColor = Colors.LightSlateGray;
titleBar.ForegroundColor = Colors.Snow;
titleBar.InactiveBackgroundColor = Colors.LightSlateGray;
titleBar.InactiveForegroundColor = Colors.White;
titleBar.ButtonBackgroundColor = Colors.LightSlateGray;
titleBar.ButtonForegroundColor = Colors.Snow;
titleBar.ButtonInactiveBackgroundColor = Colors.LightSlateGray;
titleBar.ButtonInactiveForegroundColor = Colors.White;
Try placing in your UWP app's OnLaunched method (App.xaml.cs), after the call to Window.Activate.
I'm developing wp8.1 runtime app.I need to get a textblock control's actual width to do something before a page(or an usercontrol) loaded. In the wp8 app, I can do this with using the code:
var textBlock = new TextBlock();
textBlock.FontSize = 26;
textBlock.Text = "A";
var width = textBlock.ActualWidth;
but, in the wp8.1 runtime app, the code above cannot get actual width, and it always returns 0.
Could someone tell me how to get textblock actual width before page loaded in wp8.1 runtime app?
Thanks!
I'm actually surprise it worked in WP8.0 SL so I did a little test. You're right it does work. To get it to work in WP8.1 runtime, I would add it to a Container then call UpdateLayout like below:
<Grid x:Name="ContentPanel">
<!--- content xaml --->
</Grid>
private void Page_Loaded(object sender, RoutedEventArgs e)
{
TextBlock tb = new TextBlock();
tb.Margin = new Thickness(-2500, -2500, 0, 0); // hide it using margin
tb.FontSize = 26;
tb.Text = "Test Test Test Test";
this.ContentPanel.Children.Add(tb);
tb.UpdateLayout();
var tb_width = tb.ActualWidth;
var tb_height = tb.ActualHeight;
}
I don't think you can get it before the TextBlock is actually loaded.
The thing is that the default value of ActualWidth is 0 and the default value is what you would get if the TextBlock has not yet been loaded or rendered in the UI. Reference and more details about this property can be found here.
You might be able to catch a SizeChanged event of the TextBlock and do something from there.
I want to display one or more CheckBoxes on a tile in my Windows Phone app. This works already for TextBlocks, but with a CheckBox it shows only the Text of the CheckBox and not the Checkmark itself.
This is a sample of my code:
public void CreateTile()
{
StackPanel panel = new StackPanel();
panel.VerticalAlignment = VerticalAlignment.Top;
panel.Margin = new Thickness(7.0, 7.0, 7.0, 0);
panel.Width = 336;
panel.Height = 336;
panel.Orientation = Orientation.Vertical;
// Create and add a CheckBox for each task
foreach (var task in _tasks)
{
TextBlock textBlock = new TextBlock();
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Style = App.Current.Resources["PhoneTextLargeStyle"] as Style;
textBlock.Foreground = new SolidColorBrush(Colors.White);
textBlock.Text = task.Text;
CheckBox checkBox = new CheckBox();
checkBox.IsChecked = task.IsDone;
checkBox.Content = textBlock;
panel.Children.Add(checkBox);
}
Grid layoutRoot = new Grid();
layoutRoot.Background = new SolidColorBrush(Colors.Blue);
layoutRoot.Width = 336;
layoutRoot.Height = 336;
layoutRoot.Children.Add(panel);
layoutRoot.Measure(new Size(336, 336));
layoutRoot.Arrange(new Rect(0, 0, 336, 336));
layoutRoot.UpdateLayout();
// Render grid into bitmap
WriteableBitmap bitmap = new WriteableBitmap(336, 336);
bitmap.Render(layoutRoot, null);
bitmap.Invalidate();
// Save background image for tile to isolated storage
Uri backgroundImage = TileHelper.SaveTileImage(bitmap);
}
If I create a tile with a background image created by the method above, the tile will look like this:
As you can see the text is displayed but there is no checkmark/square before the text.
I personally like to use Segoe UI Symbol as the Font Family in such situations. This gives me the flexibility to use Text and Symbols together while not messing around too much with code / images. SUS has great modern icons (or characters if you may call them) that are very much Metroish, I'd say.
Just open up Charmap (Win + R and type in charmap) and in the Font Select -> Segoe UI Symbol. Now you can select any character you like and paste into Visual Studio Editor itself. Yes, it works!
The symbol may not display properly in the Editor itself but it will at Runtime
Here are some suggestions:
Here are the corresponding characters:
☑
✅
Don't worry about them not looking right HERE. They should when you follow the above steps.
You can always "hack" it by using images of checkbox controls. Did you try to show created control in UI? i.e. adding it to page? Just to see if your code is executed correctly.
Or another solution would be to use check mark character - http://www.fileformat.info/info/unicode/char/2713/index.htm
I'll try to replicate this problem in my test app since it is strange that it does not work.
I'm trying to adapt my app for iOS 7. It's written with Xamarin and C#.
I'm having trouble with extra padding for the left button in the navigationbar.
I have a helper method for rendering my back-button which looks like this:
public static UIBarButtonItem GetBackButton (this UIViewController controller)
{
var backImage = new UIImage ("Images/back.png");
var backButton = new UIButton (UIButtonType.Custom);
backButton.Frame = new RectangleF (0, 0, 44, 44);
backButton.SetImage (backImage, UIControlState.Normal);
backButton.TouchUpInside += (object sender, EventArgs e) => {
var cancelBackNavigation = false;
if (controller is UIViewControllerBase) {
if (((UIViewControllerBase)controller).PrepareNavigateBack () != true) {
cancelBackNavigation = true;
}
}
if (cancelBackNavigation == false) {
controller.NavigationController.PopViewControllerAnimated (true);
}
};
return new UIBarButtonItem (backButton);
}
The navigationbar adds lots of padding before the back-button and making the image inside the back-button look very far away from its real position. The code above works fine in iOS 6.
I don't wanna use ContentEdgeInsets cause it will stretch the image and making it ugly.
Anyone with an idea of what to do?
I tried looking up your issue and found out that first, you need to hide the back button as follows:
NavigationItem.HidesBackButton = true;
Then for setting the button, you need to set it this way:
NavigationItem.BackBarButtonItem = yourButton;
That way, you won`t have the extra indentation.
Also you might find the following question useful:
Make a custom back button for UINavigationController
This is how I setup my NavigationBar
controller.View.BackgroundColor = Theme.BackgroundColor;
controller.NavigationItem.SetHidesBackButton (true, false);
controller.NavigationController.Toolbar.TintColor = Theme.BackgroundColor;
controller.NavigationController.NavigationBar.TintColor = Theme.BackgroundColor;
controller.NavigationController.SetNavigationBarHidden (show == false, false);
controller.NavigationController.NavigationBar.BackgroundColor = Theme.BackgroundColor;
controller.NavigationController.NavigationBar.SetTitleTextAttributes (Theme.NavigationBarTextAttributes);
controller.NavigationController.NavigationBar.Subviews [0].Alpha = 0.01f;
I'm trying to create dynamically text box in WPF. It is very essential that I will have the flexibility to determine where the text box will be - in pixel level.
I have found many answers which use stackpanel to create "run-time" text box - but couldn't find how to construct it according to specified location.
the textbox has to be "word wrap" and I'm using a button click event to create the text box
this is the code for now, I really don't know which methods or properties will be helpful.
thanks :)
private void button1_Click(object sender, RoutedEventArgs e)
{
TextBox x = new TextBox();
x.Name = "new_textbox";
x.TextWrapping= TextWrapping.Wrap;
x.VerticalScrollBarVisibility=ScrollBarVisibility.Visible;
x.AcceptsReturn = true;
x.Margin = new Thickness(5, 10, 0, 0);
}
TextBox x = new TextBox();
x.Name = "new_textbox";
x.TextWrapping= TextWrapping.Wrap;
x.VerticalScrollBarVisibility=ScrollBarVisibility.Visible;
x.AcceptsReturn = true;
x.Margin = new Thickness(5, 10, 0, 0);
HouseCanvas.Children.Add(x);
Canvas.SetLeft(x, 20);
Canvas.SetTop(x, 20);
You probably want to place it in a Canvas, if you care about pixel placement of the textbox itself. You'll need to use x.SetValue(Canvas.LeftProperty, pixelX) [and .RightProperty, etc...] to get the position exactly right. Having not done this myself, I'd guess that you need to put the canvas in the right Z-order (on top), and make it transparent. There may also be issues with events, depending on the z-order. Good luck!
-Kev