Is there a working example for drawing an image inside a steema teechart in xamarin forms? I am really struggling with this.
It doesn't work either assigning an image to the back wall or panel:
var backImage = new Image();
backImage.Source = ImageSource.FromUri(new Uri("http://www.steema.com/uploads/news/xamarinforms_280x210.png"));
tChart1.Walls.Back.Gradient.Visible = false;
tChart1.Walls.Back.Image = backImage;
tChart1.Panel.Gradient.Visible = false;
tChart1.Panel.Image = backImage;
nor drawing it directly on the canvas:
void tChart1_BeforeDrawSeries(object sender, Graphics3D g)
{
Rectangle chartRect = tChart1.Chart.ChartRect;
var backImage = new Image();
backImage.Source = ImageSource.FromUri(new Uri("http://www.steema.com/uploads/news/xamarinforms_280x210.png"));
g.Draw(chartRect, chartRect, backImage, false);
}
So I have added this to the bug list (bug 1299). Happens both in iOS and Android.
Related
So I'm new to developing in Xamarin.Forms and I was working on a project where I had multiple views in a StackLayout on one page. I was wondering if there was a way that you could specify padding differently for each different view.
For example, there is an Image that I want to fill the entire width of the screen, but there is an Entry underneath it that I do not want to fill the entire screen. However, if I use the StackLayout.Padding attribute it sets the same padding to all views.
Is there any solution to this?
EDIT:
I forgot to mention earlier that I have already tried using the margin property but keep getting the error 'Entry' does not contain a definition for 'margin'
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace HuntFishNY
{
class LandingPage : ContentPage
{
Image logo, silhouettes;
Entry username, password;
Button signIn, register;
Label title, trouble;
StackLayout heading, inputSection, footer;
public LandingPage()
{
this.BackgroundColor = Color.FromHex("#2B5237");
logo = new Image();
logo.Source = "dec_logo.png";
silhouettes = new Image();
silhouettes.Source = "sportinglicense_background.jpg";
username = new Entry();
username.HorizontalTextAlignment = TextAlignment.Start;
username.BackgroundColor = Color.White;
username.Placeholder = "Username";
username.PlaceholderColor = Color.Gray;
username.TextColor = Color.Black;
username.VerticalOptions = LayoutOptions.FillAndExpand;
password = new Entry();
password.HorizontalTextAlignment = TextAlignment.Start;
password.IsPassword = true;
password.BackgroundColor = Color.White;
password.Placeholder = "Password";
password.PlaceholderColor = Color.Gray;
password.TextColor = Color.Black;
password.VerticalOptions = LayoutOptions.FillAndExpand;
signIn = new Button();
signIn.Text = "Sign In";
signIn.BackgroundColor = Color.FromHex("#2b5237");
register = new Button();
register.Text = "Register New Account";
title = new Label();
title.TextColor = Color.FromHex("#E2AF28");
title.HorizontalTextAlignment = TextAlignment.Center;
trouble = new Label();
trouble.Text = "Having trouble signing in?";
heading = new StackLayout();
heading.VerticalOptions = LayoutOptions.Start;
heading.Children.Add(logo);
heading.Children.Add(title);
heading.Children.Add(silhouettes);
heading.Children.Add(username);
heading.Children.Add(password);
heading.Padding = new Thickness(10, 10, 20, 20);
this.Content = heading;
}
}
}
It seems you should be using a Grid(https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/grid/) instead of a StackLayout.
You can achieve different row height using RowDefinitions within a Grid.
You can also add a StackLayout inside another StackLayout.
That said, if your Entry do not have a Margin it´s probably because you're using an outdated version of Xamarin.Forms (Margin was introduced in 2.1 or 2.2. Current is 2.3)
Is there any Windows Store apps that's similar to ASP.NET ImageMap control
I want to have an image with defined clickable regions, when a region is clicked the event gets fired.
you can use this:
Image image = new Image();
image.Source = new BitmapImage(new Uri("ms-appx:///Assets/images.png"));
image.Width = 50;
image.Height = 50;
image.Tapped += new TappedEventHandler(pushpin_tapped);
MapLayer.SetPosition(image, new Location(latitude, longitude));
layer.Children.Add(image);
private void pushpin_tapped(object sender, TappedRoutedEventArgs e)
{
//you can handle your event here
}
for multiple events or ui-elements you can define a user control.Hope this can help
In Xamarin.Forms 1.3+, how do you make a ContentPage fullscreen?
The most basic exemple of a ContentPage is the one provided upon creating a Xamarin.Forms Portable project.
public App (){
// The root page of your application
MainPage = new ContentPage {
Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
More info (Android): https://developer.android.com/training/system-ui/immersive.html
Your ContentPage is fullscreen. Only the content in your ContentPage does not fill your entire screen.
You can try something like this:
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
your content page is fullscreen . You can check by changing the background color of your content page. Try this following code
BackgroundColor = Color.White
Step 1 in making a full screen is by hiding the Navigation Bar. This can be controlled while Navigating to the View.
FullScreenVideoPlayerPage fullScreenVideoPage = new FullScreenVideoPlayerPage();
NavigationPage.SetHasNavigationBar(fullScreenVideoPage, false);
await Navigation.PushAsync(fullScreenVideoPage);
Remember to use async keyword in Method Signature when using await.
private async void FullScreenVideoPlayerPage_Clicked(object sender, EventArgs e)
Step 2 is to hide the Android Status Bar. But seems this is not standard with Android. I was not fully successful in completely hiding this bar. But I could hide the status icons by:
using Android.App;
using Android.Views;
//......
// Call this method from the constructor after InitializeComponent ();
public void HideStatusBar()
{
var activity = (Activity)Forms.Context;
var window = activity.Window;
var attrs = window.Attributes;
attrs.Flags |= Android.Views.WindowManagerFlags.Fullscreen;
window.Attributes = attrs;
window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
window.AddFlags(WindowManagerFlags.Fullscreen);
var decorView = window.DecorView;
var uiOptions =
(int)Android.Views.SystemUiFlags.LayoutStable |
(int)Android.Views.SystemUiFlags.LayoutHideNavigation |
(int)Android.Views.SystemUiFlags.LayoutFullscreen |
(int)Android.Views.SystemUiFlags.HideNavigation |
(int)Android.Views.SystemUiFlags.Fullscreen |
(int)Android.Views.SystemUiFlags.Immersive;
decorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)uiOptions;
window.DecorView.SystemUiVisibility = StatusBarVisibility.Hidden;
}
protected function loadWeb():void
{
var webView:StageWebView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle(0,(navigator.actionBar.height), (systemManager.screen.width),
(systemManager.screen.height- navigator.actionBar.height-FlexGlobals.topLevelApplication.tabbedNavigator.tabBar.height));
webView.loadURL("http://www.google.com.tr");
}
I used StageWebView component to load web page,www.google.com.tr, into stage with this code. Everything is OK. But I want to use this webView with different scale for iphone and ipad. Is there any way to scale StageWebView component?
Did you try changing the scaleMode of the stage?
import flash.display.StageScaleMode;
protected function loadWeb():void
{
var webView:StageWebView = new StageWebView();
this.stage.scaleMode = StageScaleMode.EXACT_FIT;
webView.stage = this.stage;
webView.viewPort = new Rectangle(0,(navigator.actionBar.height), (systemManager.screen.width),
(systemManager.screen.height- navigator.actionBar.height-FlexGlobals.topLevelApplication.tabbedNavigator.tabBar.height));
webView.loadURL("http://www.google.com.tr");
}
I'm creating a mobile app in which I need to show a calendar with months at the top. The months are part of a component that extends from SkinnableDataContainer (and has some custom scrolling/behaviour - which is why I did'nt use a spark list). I need the months to be shown as a 'trapezium' shaped tab and so I'm using a png image as a mask in the item renderer for the component.
When the mask is not applied, it all works well - the months render, the list/data container selection works when I click on a month and so on.
When the mask is applied, it renders well, scrolling and everything else seems to work well - but when I click on a month, nothing happens visually. And from the trace statements in my code, it appears list item selection is not changing. Looks like mouse clicks are not working.
Any ideas on how to fix this?
I've looked for similar sounding questions (but ask the opposite thing) here on SO. (http://stackoverflow.com/questions/1741172/restrict-mouseevents-to-mask-in-flex-skin)
Regards,
Krishna
Code:
public class TopCalendarMonthRenderer extends LabelItemRenderer {
[Embed(source="/assets/trapezium_alpha.png")]
private static var TrapeziumMask:Class;
private static var trapeziumMaskInstance:BitmapAsset;
override protected function createChildren():void {
super.createChildren();
setLabelProperties();
createMask();
}
private function createMask():void {
if (!this.maskShape){
if (!trapeziumMaskInstance){
trapeziumMaskInstance = (new TrapeziumMask()) as BitmapAsset;
}
maskShape = new Sprite();
//maskShape.visible = false;
//maskShape.mouseEnabled = false;
maskShape.cacheAsBitmap = true;
this.cacheAsBitmap = true;
this.addChild(maskShape);
//this.hitArea = maskShape;
}
}
override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
//don't call the parent's draw: because we draw our own background
var bgColor:uint = 0x555555;
if (this.selected)
bgColor = backgroundColor;
var g:Graphics = this.graphics;
g.beginFill(bgColor);
g.drawRoundRectComplex(0, 0, unscaledWidth, unscaledHeight, 3, 3, 0, 0);
g.endFill();
//TODO: make the mask a hitArea - so the user can interact with it - HOW?
drawMask();
}
private function drawMask():void {
var g:Graphics = maskShape.graphics;
var img:BitmapData = trapeziumMaskInstance.bitmapData;
g.beginBitmapFill(img, null, false, true);
//g.beginGradientFill(GradientType.RADIAL, [0xffffff, 0xff0000], [1, 0], [0, 255]);
//g.beginFill(0xff0000);
g.drawRect(0, 0, img.width, img.height);
g.endFill();
this.mask = maskShape;
//this.hitArea = maskShape;
}
}
I finally found this:
http://aaronhardy.com/flex/displayobject-quirks-and-tips/
This explains how setting a PNG image as an alpha mask on a DisplayObject breaks mouse events.
A work around is also provided in that article - which worked for me :)