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
Related
For my project in school, I have to create a window and program that has a menu, and for the menu, I need to have a drop down menu.
The drop down menu works and all, however, I cannot seem to get it to go into the lower part of my window.
Here is my code:
var MenuWindow = new Form();
MenuWindow.Height = 300;
MenuWindow.Width = 300;
MenuWindow.Text = "Menu";
ToolBarButton Numbers = new ToolBarButton("Number of players");
ToolBar DropDownMenu = new ToolBar();
MenuItem menuItem1 = new MenuItem("1");
MenuItem menuItem2 = new MenuItem("2");
ContextMenu ContentsOfMenu = new ContextMenu(new MenuItem[] { menuItem1, menuItem2 });
DropDownMenu.Buttons.Add(Numbers);
Numbers.Style = ToolBarButtonStyle.DropDownButton;
Numbers.DropDownMenu = ContentsOfMenu;
DropDownMenu.Left = 95;
DropDownMenu.Top = 215;
DropDownMenu.Width = 100;
DropDownMenu.Height = 10;
MenuWindow.Controls.Add(DropDownMenu);
MenuWindow.Show();
As you can see I have tried to add the Height, Width, Left and Top coordinates. However, this has done no difference to where the position of this drop down menu.
I have used a ToolBar and a ToolStrip and the result is the same; I cannot move the position of the button/drop down menu.
Also if you have any suggestions on how to improve my code, please do as I am new to this part of c#.
The first thing to consider is that the name of your variable "DropDownMenu" is misleading. That variable is a ToolBar, not a drop down menu. When you're actually selecting from the drop down on your form, the control you are using is "Numbers". "Numbers" is really what should be called "DropDownMenu".
Given this, I suspect the reason you can't change the Top and Left properties of your toolbar is because it is in fact a toolbar. Toolbars just go at the extremes of their containers. It never makes sense to put them in the middle. It's odd that they even have this property, but I'm guessing that it's because they inherit from "Control". The rendering engine must simply ignore these properties. If you really must have this, take a look at Hans Passant's comment under your question.
I don't work too much with Windows Forms Controls, but I do recall that typically you're more likely to want "ComboBox" for this. And put the combo box straight on your form, bypassing any toolbars. Like this:
var label =
new Label() {
Text = "Players",
Top = 20,
Left = 20,
Width = 75
};
var combo =
new ComboBox() {
Left = label.Left + label.Width,
Top = label.Top,
Width = 150,
Height = 10
};
combo.Items.Add("1");
combo.Items.Add("2");
var MenuWindow =
new Form() {
Height = 100,
Width = 300,
Text = "Menu"
};
MenuWindow.Controls.Add(combo);
MenuWindow.Controls.Add(label);
MenuWindow.Show();
Also, since you're new, note the different style. It's not particularly better, but it's worth knowing about. Setting properties in this manner helps me block things together better. Also, it's generally okay to use the "var" keyword when it's painfully obvious what kind of variable you have. So, for instance, it is very clear that combo is a ComboBox. Consequently I just use "var". When it's even a little unclear, then write out the actual type.
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.
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?