Create TableView in Xamarin C# Visual Studio - c#

Refer to the code below, may I know what does it mean ...
When I copy to my xml project of visual studio, it is error.
Content = new TableView {
Root = new TableRoot {
new TableSection...
},
Intent = TableIntent.Settings
};

I'm assuming you are replicating the Example in Xamarin Page. The errors you are facing, is that you are not creating the ViewCell for the TableView.
Here is a working example that should get you started.
var table = new TableView();
table.Intent = TableIntent.Settings;
var layout = new StackLayout() { Orientation = StackOrientation.Horizontal };
layout.Children.Add (new Label() {
Text = "TestLayout",
TextColor = Color.FromHex("#f35e20"),
VerticalOptions = LayoutOptions.Center
});
table.Root = new TableRoot () {
new TableSection("Getting Started") {
new ViewCell() {View = layout}
}
};
Content = table;

Related

C# Changing color on label doesnt work in my stacklayout

i am using code behind visual state managers to give selected labels a background color, but this doesnt work, any idea why?
var frameStackLayoutX = new StackLayout
{
Spacing = 5
};
var vsg = new VisualStateGroup() { Name = "CommonStates" };
var vs = new VisualState { Name = "Selected" };
vs.Setters.Add(new Setter
{
TargetName = "Selected",
Property = Label.BackgroundColorProperty,
Value = Colors.Red
});
vsg.States.Add(vs);
VisualStateManager.GetVisualStateGroups(frameStackLayoutX).Add(vsg);
var LabelName = new Label();
LabelName.Text = "Jhon Doe"
LabelName .WidthRequest = 100;
LabelName .Padding = new Thickness(10, 0, 0, 0);
frameStackLayoutX.Add(LabelName );
return frameStackLayoutX;
This is inside a grid, wherei use _lines.SelectedItem = pressedItem; to make sure that I can click on my label.

How can i rewrite the title of the header of my xamarin forms app

I have the following "error": when i click a item of my menu in my app, i need to have a custom title at the header of the page, but the app show me only the text from my viewmodel thats build the items of menu:
MenuItems = new ObservableCollection<HomeMasterMenuItem>(new[]
{
new HomeMasterMenuItem { Id = 0, Label = "Buscar Redes", TargetType = typeof(FiltersNets) },
new HomeMasterMenuItem { Id = 1, Label = "Inventario", TargetType = typeof(Inventory), Image = "ic_home_orange_100_18dp.png" },
new HomeMasterMenuItem { Id = 2, Label = "Recepciones", Title = "recep", TargetType = typeof(Receptions), Image = "receptions.png" },
new HomeMasterMenuItem { Id = 3, Label = "Despachos", TargetType = typeof(ShipOuts) },
new HomeMasterMenuItem { Id = 6, Label = "Salir", TargetType = typeof(MainPage) },
});
i used a binding to write my custom test (storaged in a property) into the title of xaml byt had no results :( the text was assigned but the header kept the text from homemastermenuitem
have any idea? bye.

Label and pins not showing using Xamarin.Forms.Map

VS 2019 with all updates.
I install Xamarin.Forms.Map using nuget.
Using Xamarin Android to display a map with a pin point.
Front end XAML is
<ContentPage.Content>
<maps:Map x:Name="Map"/>
</ContentPage.Content>
In code-behind i have
public TestPage()
{
InitializeComponent();
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
map.Pins.Add(pin);
var cp = new ContentPage
{
Content = map,
};
}
Which i have followed from MSDN https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.maps.map?view=xamarin-forms.
I then click pixel_2_pie_api_28 (F5) and once the page loads it shows a map but not to the location i set (i randomly changed the position values) or the pin point or even label? What am i missing?
you have quite a few problems in your code
// you already have a map declared in your XAML, you do not need to do it again
var map = new Map(MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10)));
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
// add this to your existing XAML map, which you named "Map"
Map.Pins.Add(pin);
// you already have a ContentPage, you don't need to declare a new one
var cp = new ContentPage
{
Content = map,
};
all you need to do
var pin = new Pin()
{
Position = new Position(37, -122),
Label = "Some Pin!"
};
Map.Pins.Add(pin);
to move the map to a specific position
var span = MapSpan.FromCenterAndRadius(new Position(37, -122), Distance.FromMiles(10));
Map.MoveToRegion(span);

How to display a Dynamic type list in ListView Xamarin Form?

I am developing an application from which I am obtaining data directly from a database, these are stored inside a variable of dynamic type to later insert it in a list and be able to display it in a ListView, but at the moment of executing the application, it doesn´t show me anything on the phone. The reason why I am using a variable of Dynamic type to store the data is because the application must show in a ListView all the tables that are in the Database, even if in the future new tables are inserted into the Database.
That is the reason why I can´t leave already defined models of the structures of the tables, because I can,t know the structures of the tables that will be added in the future to the DB.
I made an example of what I'm trying to do with a Dynamic type list, but it does not show me the data on the screen. I would really appreciate it if you could help me solve it.
public partial class MainPage : ContentPage
{
private ListView lv_inst;
private StackLayout st_inst, stk1;
public MainPage()
{
Title = "List";
CreateGUIAsync();
}
public void CreateGUIAsync()
{
lv_inst = new ListView()
{
HasUnevenRows = true,
ItemTemplate = new DataTemplate(typeof(ResultCell10))
};
var stk_2 = new StackLayout()
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.Center,
Children =
{
lv_inst
}
};
st_inst = new StackLayout()
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children =
{
stk_2
}
};
Content = st_inst;
}
protected override async void OnAppearing()
{
base.OnAppearing();
try
{
lv_inst.IsVisible = false;
List<dynamic> list = new List<dynamic>();
dynamic dObj = new ExpandoObject();
dObj.id = "1";
dObj.name = "Juan";
dObj.surname = "Moreno";
dObj.age = "22";
list.Add(dObj);
lv_inst.ItemsSource = list;
lv_inst.IsVisible = true;
}
catch (Exception e) { await DisplayAlert("", e.StackTrace, ""); }
}
}
class ResultCell10 : ViewCell
{
public ResultCell10()
{
int heigh = 35;
List<String> propierty = new List<string>();
List<Label> lLabel = new List<Label>();
propierty.Add("id");
propierty.Add("name");
propierty.Add("surname");
propierty.Add("age");
var i = 0;
foreach (var p in propierty)
{
lLabel.Add(
new Label()
{
FontSize = 10,
HeightRequest = heigh,
WidthRequest = 60,
TextColor = Color.Black,
FontFamily = "Roboto"
}
);
lLabel[i].SetBinding(Label.TextProperty, p);
i++;
}
var stackList = new StackLayout
{
Padding = new Thickness(10),
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
foreach (var l in lLabel)
{
stackList.Children.Add(l);
}
View = stackList;
}
}
}
not being able to use dynamic objects is mentioned in the official Xamarin docs. Keith from Wintellect, wrote a detailed article here which states
Apple does not allow apps to generate executable code at runtime, because this would be a potentially major security vulnerability. Prior to iOS 8, that was the rule with no exceptions. However as of iOS 8, they loosened it up slightly. You can now dynamically load pre-compiled libraries, but they still don’t allow any form of “compilation” to take place on the device itself. You can also alter an application’s execution at runtime based on a script interpreter or similar technology—but that’s not quite the same thing.

How to customize a tooltip for each individual datapoint in a wpf toolkit lineseries chart?

I have seen several questions about doing a custom tooltip for a single line series.
I need a custom tool-tip for each data-point. I would like to add more to the tool-tip than just the dependent value path and the independent value path.
Example I have 2 data points on the same line one with a value(Y-axis)
of 2, date(x-axis) of 4/28/2016, and configuration of A. The other has
a value of 3, date of 4/29/2016, and configuration of B.
How would I also show the configurations? This is all done in code behind because I have a dynamic number of lineseries. So I can't just assign a style to each lineseries in the xaml.
var MyLineSeries = new LineSeries();
lMyLineSeries.DependentValuePath = "Y";
lMyLineSeries.IndependentValuePath = "X";
lMyLineSeries.DataPointStyle = lToolTipDataPointStyle;
This is my code for creating the tool tip style.
var lToolTipDataPointStyle = new Style(typeof(LineDataPoint));
var lTemplate = new ControlTemplate(typeof(LineDataPoint));
var lGridElement = new FrameworkElementFactory(typeof(Border));
//Tooltip
var lStackPanel = new StackPanel();
var lValueContentControl = new ContentControl();
lValueContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.DependentValuePath));
lValueContentControl.ContentStringFormat = "Value: {0}";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding())//This is what Idk what to bind to???
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";
lStackPanel.Children.Add(lValueContentControl);
lStackPanel.Children.Add(lConfigurationContentControl);
lGridElement.SetValue(ToolTipService.ToolTipProperty, lStackPanel);
var lEllipseElement = new FrameworkElementFactory(typeof(Ellipse));
lEllipseElement.SetValue(Ellipse.StrokeThicknessProperty, new TemplateBindingExtension(Border.BorderThicknessProperty));
lEllipseElement.SetValue(Ellipse.StrokeProperty, new TemplateBindingExtension(Border.BorderBrushProperty));
lEllipseElement.SetValue(Ellipse.FillProperty, new TemplateBindingExtension(Grid.BackgroundProperty));
lGridElement.AppendChild(lEllipseElement);
lTemplate.VisualTree = lGridElement;
var lTemplateSetter = new Setter();
lTemplateSetter.Property = LineDataPoint.TemplateProperty;
lTemplateSetter.Value = lTemplate;
lToolTipDataPointStyle.Setters.Add(lTemplateSetter);
return lToolTipDataPointStyle;
I figured it out by using the Tag on the Line series.
myLineSeries.Tag = "Configuration";
var lConfigurationContentControl = new ContentControl();
lConfigurationContentControl.SetBinding(ContentControl.ContentProperty, new Binding(myLineSeries.Tag.ToString()))
lConfigurationContentControl.ContentStringFormat = "Configuration: {0}";

Categories

Resources