MonoTouch.Dialog: ContentSizeForViewInPopover changes in Date - xamarin.ios

I have a Reflection-created dialog that looks like below. When the date is clicked, the popover changes shape and renders the datepicker squished, see below too.
My Class is below for reference.
[Preserve(AllMembers = true)]
public class EventEntity
{
[Section("Date of Measurement", "")]
[Indexed]
[Date]
public DateTime Date ;
[Section("Measurement Details", "")]
[Caption("Height")]
[Entry(Placeholder= "Centimeters",KeyboardType = UIKeyboardType.PhonePad)]
public string HeightCM ;
[Caption("Weight")]
[Entry(Placeholder= "Kilograms",KeyboardType = UIKeyboardType.PhonePad)]
public string WeightKG ;
[Caption("Head Circumference")]
[Entry(Placeholder = "Centimeters", KeyboardType = UIKeyboardType.PhonePad)]
public string HeadCircumferenceCM;
[Skip]
public int ChildFK ;
[Skip]
[PrimaryKey, AutoIncrement]
public int PK;
}

If you provide me with a self-contained test case, I could look into debugging that. I never really used MonoTouch.Dialog in the iPad ;-)

Related

How to use fieldset in lightning Component

I want to create a custom lightning component to create new Case records and need to use fieldset to include fields in component. Need to use this only for one object. I never used fieldsets so dont have any idea on it. It would be really great if you can share some sample code or any link for the same.
You can use this utility class
This is the wrapper class to hold the meta info about the fields
public with sharing class DataTableColumns {
#AuraEnabled
public String label {get;set;}
#AuraEnabled
public String fieldName {get;set;}
#AuraEnabled
public String type {get;set;}
public DataTableColumns(String label, String fieldName, String type){
this.label = label;
this.fieldName = fieldName;
this.type = type;
}
}
Class FieldSetHelper has a method getColumns () this will return the list of DataTableColumns wrapper containing the information about the filedset columns
public with sharing class FieldSetHelper {
/*
#param String strObjectName : required. Object name to get the required filed set
#param String strFieldSetName : required. FieldSet name
#return List<DataTableColumns> list of columns in the specified fieldSet
*/
public static List<DataTableColumns> getColumns (String strObjectName, String strFieldSetName) {
Schema.SObjectType SObjectTypeObj = Schema.getGlobalDescribe().get(strObjectName);
Schema.DescribeSObjectResult DescribeSObjectResultObj = SObjectTypeObj.getDescribe();
Schema.FieldSet fieldSetObj = DescribeSObjectResultObj.FieldSets.getMap().get(strFieldSetName);
List<DataTableColumns> lstDataColumns = new List<DataTableColumns>();
for( Schema.FieldSetMember eachFieldSetMember : fieldSetObj.getFields() ){
String dataType =
String.valueOf(eachFieldSetMember.getType()).toLowerCase();
DataTableColumns datacolumns = new DataTableColumns(
String.valueOf(eachFieldSetMember.getLabel()) ,
String.valueOf(eachFieldSetMember.getFieldPath()),
String.valueOf(eachFieldSetMember.getType()).toLowerCase() );
lstDataColumns.add(datacolumns);
}
return lstDataColumns;
}
}
After you getting all those field set information the create lightning component dynamically

JSF - inputText - default value

I have a question. If I want to display on start in h:inputText a "default value" should i do second getter with default value?
for ex.: my entity has field:
private int yellowCards;
public int getYellowCards() {
return yellowCards;
}
public void setYellowCards(int yellowCards) {
this.yellowCards += yellowCards;
}
in db there is 3 yellow cards. Now I want to add another stats for this Entity - next yellow card. but I don't want to have in inputText on view "3" but default "0". Is there something way to set "default" value of this field or only add second getter for this view?(because in other view i need to use this first getter to display all stats).
Use the the callback method of the bean : #PostConstruct, this will allow you to do the stuff before the page gets rendered :
private int yellowCards;
#PostConstruct
public void init(){
yellowCards = 0;
}
// getter/setter
#Field
private int minutesPlayed;
#Transient
private int STATminutesPlayed;
public int getSTATminutesPlayed() {
return 90;
}
public void setSTATminutesPlayed(int STATminutesPlayed) {
setMinutesPlayed(STATminutesPlayed);
}
public int getMinutesPlayed() {
return minutesPlayed;
}
public void setMinutesPlayed(int minutesPlayed) {
this.minutesPlayed += minutesPlayed;
}
I think is the best way to do it. STAT field and getter/setter for adding stats, and minutesPlayed with getter/setter for future display all of stats and alternatively edit them in other view.

Give a start value to a get/set variable

Is it possible to give a start value to a variable that has a get and setter? So it should look something like this:
public static float myVariable = 10 {get; set;};
Thanks in advance.
Edit:
Working in C#
Edit 2:
So I tried this:
public static class GlobalVariables {
public static float groundSearchRayDistance{get;}
static GlobalVariables()
{
groundSearchRayDistance = 10;
}
}
But it doesn't work.
Try this:
public class ClassName{
public ClassName(){
myVariable = 10;
}
public static float myVariable {get; set;}
}
Dunno what language you are using, but usually you would put that within the constructor. You would just override the constructor of that variable to take a number and make that the initial value. Hope that helps! if not, give details!

How to get a string representation of a property name of a Model in MVC3?

I have the following model:
Public Class MyModel
Public Property MyModelId As Integer
Public Property Description As String
Public Property AnotherProperty As String
End Class
Is there a method to get a property name of the Model as a string representation like the following code?
Dim propertyName as String = GetPropertyNameAsStringMethod(MyModel.Description)
So the propertyName variable has "Description" as value.
Check the Darin Dimitrov' answer on this SO thread - Reflection - get property name.
class Foo
{
public string Bar { get; set; }
}
class Program
{
static void Main()
{
var result = Get<Foo, string>(x => x.Bar);
Console.WriteLine(result);
}
static string Get<T, TResult>(Expression<Func<T, TResult>> expression)
{
var me = expression.Body as MemberExpression;
if (me != null)
{
return me.Member.Name;
}
return null;
}
}
Hope this help..
Here is a helper extension method you can use for any property:
public static class ReflectionExtensions
{
public static string PropertyName<T>(this T owner,
Expression<Func<T, object>> expression) where T : class
{
if (owner == null) throw new ArgumentNullException("owner");
var memberExpression = (MemberExpression)expression.Body;
return memberExpression.Member.Name;
}
}
However, this will only work on instances of a class. You can write a similar extension method that will operate directly on the type instead.
You need to do it using reflection.
There are already loads of posts on stack overflow like this:
How to get current property name via reflection?
Reflection - get property name
Get string name of property using reflection
Reflection - get property name
I believe that the answer will be along the lines of:
string prop = "name";
PropertyInfo pi = myObject.GetType().GetProperty(prop);
Create an extension method and then use it where needed.
Private Shared Function GetPropertyName(Of T)(exp As Expression(Of Func(Of T))) As String
Return (DirectCast(exp.Body, MemberExpression).Member).Name
End Function
have a look at this post as well.
I have solved this issue editing a bit #NiranjanKala's source example,
converting the code in vb.Net like this
<System.Runtime.CompilerServices.Extension()> _
Public Function GetPropertyName(Of T, TResult)(expression As Expression(Of Func(Of T, TResult))) As String
Dim [me] = TryCast(expression.Body, MemberExpression)
If [me] IsNot Nothing Then
Return [me].Member.Name
End If
Return Nothing
End Function
Then I am able to call the extension like this
Dim propertyName as String = GetPropertyName(Of MyModel, String)(Function(x) x.Description)
Then propertyName variable has "Description" as string value.

Name generator using Generics

I am trying to generate a Name based on type of an object. In my system, I have,
class Employee {}
Class ContractEmp:Employee{}
class Manager:Employee{}
I am trying to generate name which looks like ContractEmp1 Where 1 will come from incrementer. I am trying to use Generics.
Any Help
Thank you,
With an extension method you could do something like this:
public static class NameExtension
{
private static Dictionary<string, int> counters = new Dictionary<string, int>();
public static string MakeUpName<T>(this T #object)
{
var t = typeof(T);
if ( ! counters.ContainsKey(t.FullName))
counters[t.FullName] = 0;
return t.Name + counters[t.FullName]++;
}
}
Test:
[TestFixture]
class NameTest
{
[Test]
public void test()
{
Console.WriteLine(new NameTest().MakeUpName());
Console.WriteLine(new NameTest().MakeUpName());
Console.WriteLine(new NameTest().MakeUpName());
Console.WriteLine(new NameTest().MakeUpName());
}
}
Output:
NameTest0
NameTest1
NameTest2
NameTest3
You can use a private static int in the Employee class which gets incremented on each constructor call. Combining this number with the typeof(this).Name value you can generate the names as described. Do note that the counter will count for all Employee extending classes so if you want an consecutive list of numbers for each Employee extending class, a specific counter should be implemented for every extending class. Also, the counters will be set to zero each time the application restarts.
public Class ContractEmp:Employee{
private static int counter = 1;
private String name = "";
public ContractEmp() {
name = typeof(this).Name + counter++;
}
}
Something like this should work!

Resources