Can't access Xamarin CustomPin's attributes - xamarin.forms

Im using Xamarin.Forms.Maps to create Pins on a Map.
This is the Custom Pin im trying to use.
public class CustomPin : Pin
{
public string Name { get; set; }
public string Url { get; set; }
}
after I add one of my custom pins to my map this function gets called automatically on the CustomMapRenderer inside the android project. which lets me set things about the pin(which is called Marker in android for some reason).
protected override MarkerOptions CreateMarker(Pin pin)
{
var marker = new MarkerOptions();
marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
marker.SetTitle(pin.Label);
marker.SetSnippet(pin.Address);
marker.SetIcon(BitmapDescriptorFactory.FromAsset("imagenBITMAP.bmp"));
return marker;
}
the problem is... I'm trying to access the (Pin pin) with something like this
var testVar = pin.Name; to choose a different marker.SetIcon image depending on the name that the pin has. but pin. doesnt bring up the attributes of the CustomPin.
This is what pin shows when debuggin step by step:

you have to cast it to the correct type first
var custom = (CustomPin)pin;
if (custom.Name == "...")

Related

How to set certain icon instead of default pins?

I'm trying to use certain icon instead of default Xamarin.Forms pins on Map.
So I created CustomisePin class that inheritance Pin.
using Xamarin.Forms.Maps;
namespace agroNet.Tools
{
public class CustomPin : Pin
{
public string PinIcon { get; set; }
}
}
Here is what I tried in my ViewModel
private Map _map;
public IrrigNetViewModel(Map map)
{
dialog = UserDialogs.Instance.Loading(AppResource.LocalizationResource.Loading);
TabTappedCommand = new Command((tabName) => OnTapClicked(tabName.ToString()));
HideListOnTapCommand = new Command(HideListOnTap);
_map = map;
GetData();
}
And here is method wor set pins on positions.
public void LoadMapTab()
{
//var irrigNetPins = new List<CustomPin>();
foreach (var item in IrrigNetCollection)
{
//var pins = new CustomPin
//{
// Label = item.StationName,
// Position = new Position(item.StationLatitude, item.StationLongitude),
// PinIcon = "satellite.png"
//};
_map.Pins.Add(new CustomPin
{
Label = item.StationName,
Position = new Position(item.StationLatitude, item.StationLongitude),
//PinIcon = P
});
_map.MoveToRegion(
MapSpan.FromCenterAndRadius(new Position(item.StationLatitude, item.StationLongitude),
Distance.FromKilometers(30)));
//irrigNetPins.Add(pins);
}
//return irrigNetPins;
}
In LoadMapTab under the comment lines is what I have tried to set pin icon.
And here is part of View if it's important because of Binding Context.
public partial class IrrigNetPage : ContentPage
{
public IrrigNetPage()
{
InitializeComponent();
BindingContext = new IrrigNetViewModel(MainMap);
}
}
I find some examples on Google, like:
https://github.com/raechten/BindableMapTest
https://github.com/paulpatarinski/ShouldIWashMyCar
For some reason I can't event run them, but still I tried to use code and no matter what I have Pin are alwas default, or not even show.
What is simple way to set certain icon for pin and is it posiple to render it just with some path to the icon without rendering map also (Because I saw many create costumise map for customised pins).
Also If it's important for someon I'm using MVVM patern.
The official Xamarin sample and documentation is outdated. I modified the official Custom Pin sample in order to use custom pins in iOS and Android. The project is hosted on GitHub.
An issue is reported about the official sample over here.

Enabling and disabling specific buttons in and Enum in C#

i have this enum called ScoreType.
public enum ScoreType {
Ones, Twos, Threes, Fours, Fives, Sixes,
SubTotal, BonusFor63Plus, SectionATotal,
ThreeOfAKind, FourOfAKind, FullHouse,
SmallStraight, LargeStraight, Chance, Yahtzee,
YahtzeeBonus, SectionBTotal, GrandTotal
}
I would like to in the EnableScoreButton method to enable the specified button corresponding to the ScoreType parameter of 'combo'.
public void EnableScoreButton(ScoreType combo) {
//SOMTHING.Enabled = true;
}
Could you please show me how to do this?

Implement "Navigation bar" for custom editor

When registering a custom language service extension, Visual Studio creates a new options entry for the language within the Text Editor node (in the Visual Studio options dialog). Beneath that node two default nodes are created named General and Tabs, whereby the General tab contains statement completion and display settings...
In the Dispay group there are three options; one of them is the Navigation Bar checkbox (which shows/hides the editor´s navigation bar). For my custom language service, this option is disabled. Of course, it´s not implemented yet.
I would like to know, what I have to do, to provide a navigation bar for my custom editor... I guess that there is a certain interface I have to implement in the editor´s factory, or the language service package must export a certain MEF component, or, or, ...
Jon Senchyna´s answer guided me into the right direction. The OnSynchronizeDropdowns method gets never called (the SDK documentation is just wrong in that case). What did the final trick was to override at least GetComboAttributes, GetEntryAttributes and GetEntryText to get text-only items for both combo boxes...
[ComVisible(true)]
public sealed class CustomTypeAndMemberDropdownBars : TypeAndMemberDropdownBars
{
private readonly IList<string> declarations;
private readonly IList<string> members;
public CustomTypeAndMemberDropdownBars(
LanguageService languageService,
IVsTextView view)
: base(languageService)
{
// TODO: initialize declarations and members from the given text view...
this.declarations = ...
this.members = ...
}
private enum ComboIndex
{
Types = 0,
Members = 1
}
public override int GetComboAttributes(
int combo,
out uint entries,
out uint entryType,
out IntPtr imageList)
{
entries = 0;
imageList = IntPtr.Zero;
entryType = (uint)DROPDOWNENTRYTYPE.ENTRY_TEXT;
var comboType = (ComboIndex)combo;
switch (comboType)
{
case ComboIndex.Types:
entries = (uint)this.declarations.Count();
break;
case ComboIndex.Members:
entries = (uint)this.members.Count();
break;
}
return VSConstants.S_OK;
}
public override int GetEntryAttributes(
int combo,
int entry,
out uint fontAttrs)
{
fontAttrs = (uint)DROPDOWNFONTATTR.FONTATTR_PLAIN;
return VSConstants.S_OK;
}
public override int GetEntryText(
int combo,
int entry,
out string text)
{
text = null;
var comboType = (ComboIndex)combo;
switch (comboType)
{
case ComboIndex.Types:
text = this.declarations[entry];
break;
case ComboIndex.Members:
text = this.members[entry];
break;
}
return VSConstants.S_OK;
}
public override bool OnSynchronizeDropdowns(
LanguageService languageService,
IVsTextView textView,
int line,
int col,
ArrayList dropDownTypes,
ArrayList dropDownMembers,
ref int selectedType,
ref int selectedMember)
{
return false;
}
}
I believe the following steps should be what you need:
In your Package class, set the ShowDropDownOptions property to true in the ProvideLanguageService attribute
Create a class that implements TypeAndMemberDropdownBars
In your LanguageService class, implement the CreateDropDownHelper function and have it return an instance of your TypeAndMemberDropdownBars

AutoMapper: Can't access original object instances passed to Map() from within AfterMap()

I have code like this:
//Fields
Product _prod, _existingProd;
void Test()
{
_prod = MakeAndPopulateSomeRandomProduct();
_existingProd = GetProdFromDb(1);
Mapper.CreateMap()
.AfterMap((s, d) =>
{
Console.WriteLine(d==_existingProd); //Why does this print false?
//Customize other properties on destination object
});
Mapper.Map(_prod, _existingProd);
}
When I call Test(), false is printed but I expected true. In my scenario, it is important to be able to access the original destination object via the AfterMap argument. I only included the fields to demonstrate the problem but in my real code, I don't have direct access to them. How can I access the object instances passed in to Map() when customizing the mapping?
The following example works. Probably you are using some type converter which creates new instance... Also please provide all mapping configurations to better understand the problem.
[TestFixture]
public class AfterMap_Test
{
//Fields
private Product _prod, _existingProd;
[Test]
public void Test()
{
Mapper.CreateMap<Product, Product>()
.AfterMap((s, d) =>
{
Trace.WriteLine(d == _existingProd); //Why does this print false?
//Customize other properties on destination object
});
_existingProd = new Product {P1 = "Destination"};
_prod = new Product {P1 = "Source"};
Mapper.Map(_prod, _existingProd);
}
}
internal class Product
{
public string P1 { get; set; }
}

Camera Stream in Flash Problem

Please help me fill the question marks. I want to get a feed from my camera and to pass it to the receive function. Also in flash builder(in design mode) how do I put elements so they can play a camera feed?? Because as it seems VideoDisplay just doesn't work
public function receive(???:???):void{
//othercam is a graphic element(VideoDisplay)
othercam.??? = ????;
}
private function send():void{
var mycam:Camera = Camera.getCamera();
//mycam2.attachCamera(mycam);
//sendstr is a stream we send
sendstr.attachCamera(mycam);
//we pass mycam into receive
sendstr.send("receive",mycam);
}
public function receive():void
{
video = new Video(put-width-here, put-height-here);
video.attachCamera(mycam); // mycam needs to be a class variable, not local to "send()";
mybitmap = new BitmapData(fill parameters here);
update();
}
public function update() {
mybitmap.draw(video);
// do stuff to your bitmap here...
}

Resources