I want to animate lives tiles in UAP applications. But I am getting this exception:
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
I am using this code:
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = new TileImageSource("Assets/Apps/Hipstame/hipster.jpg")
},
Children =
{
new TileText() {Text =Description, Wrap = true, Style = TileTextStyle.BodySubtle}
}
};
How can I animate my live tiles?
Cannot implicitly convert type 'NotificationsExtensions.Tiles.TileImageSource' to 'string'.
The reason you are getting this exception is because as of May 2016 NotificationsExtensions received some updates where there have been changes made to TileBackgroundImage and TilePeekImage. You can see the details of these changes here in the msdn update post.
Specifically, the property type for Source changed from TileImageSource to string. This change means that you need to change the way you are setting Source. Note in the code below (yours, which I modified) where the Source is simply a string. This should resolve the exception you are getting.
TileBindingContentAdaptive largebindingContent = new TileBindingContentAdaptive()
{
PeekImage = new TilePeekImage()
{
Source = "Assets/Apps/Hipstame/hipster.jpg"
},
Children =
{
new TileText()
{
Text = Description,
Wrap = true,
Style = TileTextStyle.BodySubtle
}
}
};
As far as animating your live tiles there are a variety of things you can do and I cannot give any specific advice unless you specify what you want to do with your tiles. For example, if you want to cycle through images in your live tile you can take a look at this example here for cycling multiple images with an animation through a live tile. You can also refer to the msdn Adaptive Tile Templates documentation if you want to read through in more detail about what else you can do with your tiles.
Related
I am using LiveCharts.WinForms.CartesianChart and load it with a GLineSeries. What I want to do, is to zoom to specific region of the X-Axis. Is it somehow possible in LiveCharts?
I could not find any method CartesianChart doing that.
I have found a way to do that. I think the MinValue and MaxValue mentioned in the comments will perhaps work, too. But instead of changing the MinValue and MaxValue directly, I found another way. You can bind the CartesianChart to a BindingAssistant. There you can set the From and To Value. Then the CartesianChart is automatically zoomed to the region.
The code would look like this:
var assistant = new BindingAssistant
{
From = ZoomDateStart.Ticks,
To = ZoomDateEnd.Ticks
};
cartesianChart1.AxisX[0].SetBinding(Axis.MinValueProperty,
new Binding { Path = new PropertyPath("From"), Source = assistant, Mode = BindingMode.TwoWay });
cartesianChart1.AxisX[0].SetBinding(Axis.MaxValueProperty,
new Binding { Path = new PropertyPath("To"), Source = assistant, Mode = BindingMode.TwoWay });
The advantage of using this method is that now the chart can also be made scrollable. For more info: Example
Is there a way to set multiple image style for bot detect captcha?
I am referring to this sample.
I have written an extension class to initialize captcha,
public class CaptchaHelper
{
public static MvcCaptcha GetTicketsCaptcha()
{
// create the control instance
MvcCaptcha myCaptcha = new MvcCaptcha("ExampleCaptcha");
myCaptchaImageStyle = BotDetect.ImageStyle.AncientMosaic;
}
}
I can set one style, but cannot find a way to set multiple options. Need some help?
There is a way to do this, "CaptchaRandomization.GetRandomImageStyle" accepts ImageStyle array.
ImageStyle[] allowedStyles =
{
ImageStyle.AncientMosaic,
ImageStyle.MeltingHeat,
ImageStyle.MeltingHeat2,
ImageStyle.Negative
};
myCaptcha.ImageStyle = CaptchaRandomization.GetRandomImageStyle(allowedStyles);
More details
I am trying add a background image using the image property in button. The issue I'm facing is that i can't set StreamImageSource as button background. I encountered the error given below if I try to do so.
The Code I use to set Image:
ImageSource iconsource =ImageSource.FromStream(() => new MemoryStream(ImgASBytes));
Button Icon = new Button ();
Icon.Image = iconsource ;
The Error I encounter:
Error CS0266: Cannot implicitly convert type 'Xamarin.Forms.ImageSource' to 'Xamarin.Forms.FileImageSource'. An explicit conversion exists (are you missing a cast?)
ImageSource.FromStream () returns a StreamImageSource (see docs). Button.Image accepts only FileImageSource (see docs).
It means that what you're trying to achieve won't work, no matter how hard you try to cast one into the other.
Button.Image will accept images stored as resources in your platform projects, and loaded either with:
Icon.Image = ImageSource.FromFile ("foobar.png");
or
Icon.Image = "foobar.png";
The accepted answer is true that you can't cast StreamImageSource to FileImageSource, I think that the real question is about how to share images in a PCL and use them on a button, just like one would when creating an Image forms control.
The answer is to have a Grid which contains both a Button and an Image object, where the Image overlaps the Button.
For example, the C# code might look like this:
ImageSource imageSource = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));
Button iconButton = new Button ();
iconButton.VerticalOptions = LayoutOptions.FillAndExpand;
iconButton.HorizontalOptions = LayoutOptions.FillAndExpand;
var image = new Image();
image.Source = imageSource;
// So it doesn't eat up clicks that should go to the button:
image.InputTransparent = true;
// Give it a margin so it doesn't extend to the edge of the grid
image.Margin = new Thickness(10);
var grid = new Grid();
// If we don't set a width request, it may stretch horizontally in a stack
grid.WidthRequest = 48;
// Add the button first, so it is under the image...
grid.Children.Add(iconButton);
// ...then add the image
grid.Children.Add(image);
You may have to play with the sizes and thickness values but this should get you a clickable button with an icon.
As of Xamarin.Forms 3.4.0 you can now use ImageButton. You can use embedded images by using an extension method explained in this MS document
Careful with upper- and lowercase in filenames.
I was wondering, why my button-images were shown properly on the simulator, but not on my iPhone.
On the device the filename must match exactly, the simulator doesn't care about upper- and lowercase in filenames.
I use this and it works
var imageA = new Image();
imageA.Source=(FileImageSource)ImageSource.FromFile(allergeneLocation)};
or
var imageA = new Image()
{
BackgroundColor = Color.Teal,
Source = (FileImageSource)ImageSource.FromFile(allergeneLocation)},
};
Here is what I tried:
Button refreshBut = new Button
{
Image = (FileImageSource)
(ImageSource.FromFile("refreshBut.png"))
};
While it compiles I then get an unhandled null reference exception with the description: Object reference not set to an instance of an object. I am not sure if this will help anyone else try to solve this but I am at the same wall.
I've created a view that will need to be added to several different screens. I'm struggling to figure out how to align the elements correctly in the view.
The output needs to look like the following:
I've tried the following with no success:
var uiiv = new UIImageView(image);
var firstLine = new UITextField { Text = description};
var secondLine = new UITextField { Text = summary};
this.Add(uiiv);
this.Add(firstLine );
this.Add(secondLine );
Every UI element should have a Frame property that allows you to specify the position of the element relative to it's parent view. Using this property will allow you to position the element.
I have been using MT.D for some time now to make table-based UI layouts. However, I have found that XibFree is awesome for laying out custom pages while keeping the layout code as code (rather than using a designer). This is for (a) easy customization through code and (b) maintainability by other developers.
I would like to use both at the same time. XibFree's table creation isn't as easy to use as MT.D but I can't find a way to extract a UIView from a section and place it into my XibFree layout (all I need is a UIView to do this).
Any ideas? I've tried using the View from the DVC, and the TableView from the RootElement, but no luck with getting either to display in my layout.
Example:
new NativeView()
{
// table view from RootElement - shows empty space where table should be
View = entryView.TableView
},
I've also tried adding a UITableView to my view, and setting the TableView property of the DVC to that, with a call to ReloadData(), with no success.
I was able to get it to load this way:
var re = new RootElement ("") {
new Section("Please Sign In")
{
(userName = new EntryElement("User name", "Your user name", "")),
(password = new EntryElement("Password", "Your password", "", true))
}
};
var entryView = new DialogViewController (re, false);
//entryView.
var uitv = new UITableView (RectangleF.Empty, UITableViewStyle.Grouped);
entryView.LoadView ();
//entryView.TableView = uitv;
re.TableView.Frame = RectangleF.Empty;
uitv = re.TableView;
Then in my layout:
new NativeView()
{
View = uitv,
LayoutParameters = new LayoutParameters()
{
Width = AutoSize.FillParent,
Height = 200
}
},
Which gives me a scrollable region inside the view:
The region with the lines is its own scrollable view, which I did not expect given I was just giving the area the table view from the one section I created. I want to take the sections out of it and insert them into my view, so there is no scrollable view inside my view. (Never mind the weird look of the UITextfields, I'm using Pixate to style stuff.)
I hope it's just something small I am missing here and that this should be a trivial task.
EDIT: Is there also a way to calculate the height for the rendered section, to give to the LayoutParameters object?