I'm creating a simple composite control that has AJAX functionality. When trying to implement a MaskedEditValidator, the DisplayMoney property doesn't work. The MaskedEdit renders, without the dollar sign attached. Any ideas? Here's my code:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
priceTextbox.ID = this.ID + "_price";
quantityTextbox.ID = this.ID + "_quantity";
timeTextbox.ID = this.ID + "_time";
submitButton.ID = this.ID + "_submit";
submitButton.Text = "Submit";
priceMask.TargetControlID = priceTextbox.ClientID.ToString();
priceMask.ID = priceMask.TargetControlID.ToString() + "_extender";
priceMask.BehaviorID = "priceMaskExtender";
priceMask.Mask = "99.99";
priceMask.DisplayMoney = MaskedEditShowSymbol.Left;
}
Try adding the following line:
priceMask.MaskType = MaskedEditType.Number;
Optionally, set ClearMaskOnLostFocus to false if that is the behavior you want (it keeps the dollar sign even when not focused).
The DisplayMoney property setter only sets the property if MaskType is equal to MaskedEditType.Number.
set
{
if (MaskType == MaskedEditType.Number)
{
SetPropertyValue("DisplayMoney", value);
}
}
The DisplayMoney property setter only sets the property if MaskType is equal to MaskedEditType.Number.
set
{
if (MaskType == MaskedEditType.Number)
{
SetPropertyValue("DisplayMoney", value);
}
}
So you need to set:
priceMask.MaskType = MaskedEditType.Number;
Related
To be honest, I have no idea why the variable is being set to null. The object is set, then once I go through the DisplayPromptAsync, it sets the object to null.
I'm not sure what to try as I've never come across this issue.
Here's a gif of the issue. Once I enter into the field and press submit, an object gets reset.
async void OpenContainerItem()
{
// Pause the timer
blnTimerActive = false;
if (SelectedItem != null)
{
if (SelectedItem.intQuanChecked == SelectedItem.intQuantity)
return;
try
{
int intQuantity = 0;
// Ask for quantity
string result = await Application.Current.MainPage.DisplayPromptAsync("Quantity",
"How many " + SelectedItem.objItem.strItemName + " did you count?",
"Okay", cancel: "Cancel",
placeholder: "Quantity",
keyboard: Keyboard.Numeric);
// Check if it's been cancelled
if (result != null)
{
// check if theres nothing entered
if (result == "")
{
// Why tho?
await Application.Current.MainPage.DisplayAlert("Error", "Please enter a quantity.", "Okay");
}
else
{
intQuantity = int.Parse(result);
if (0 > ((SelectedItem.intQuantity - SelectedItem.intQuanChecked) - intQuantity))
{
Application.Current.MainPage.DisplayAlert("Error", "Thats too many items!", "Okay");
Reload();
blnTimerActive = true;
return;
}
modDatabaseUtilities.ContainerItemsPreCheck(SelectedItem.intContainerItemID, intQuantity, strCurrentUser);
Reload();
}
}
}
catch(Exception ex)
{
Application.Current.MainPage.DisplayAlert("Error", "Couldn't process this change. Please try again.", "Okay");
}
}
#ScottUphus - Is SelectedItem bound to a ListView? (If it is bound to anything, you should add that xaml in your question.) If so, then its a common problem: xamarin sets it back to null when the display layout is refreshed. (I'm not sure the exact "rule" for when it happens. In your case, I suspect the modal interaction causes this.)
This is how I solve such issues:
public MyItemType ValidSelectedItem { get; private set; }
public MyItemType SelectedItem
{
get => _SelectedItem;
set {
... your current setter code here ...
// Remember most recent non-null value.
if (value != null)
ValidSelectedItem = value;
}
}
private MyItemType _SelectedItem;
ValidSelectedItem remembers the non-null item, even if xamarin resets the selection back to null. Use it in code that needs that value.
Is there a difference in using "Okay" or "OK" in DisplayPromptAsync ? try to change it in your code.
this is default Page.DisplayPromptAsync Method:
public System.Threading.Tasks.Task<string> DisplayPromptAsync
(
string title,
string message,
string accept = "OK",
string cancel = "Cancel",
string placeholder = default,
int maxLength = -1,
Xamarin.Forms.Keyboard keyboard = default,
string initialValue = ""
);
Design:
If i don't have any land component price/flight prices to be added, i want the system to dispose the unused controls and move up to fill in the empty spaces, but somehow or rather, it became like this.
Result:
if (bf.landComponent != 0.00m)
{
lblLandComponent.Text = "" + bf.landComponent;
lblLandComponent.Visible = true;
lblLandComponentL.Visible = true;
}
else
{
lblLandComponent.Dispose();
lblLandComponentL.Dispose();
}
if (bf.flightComponent != 0.00m)
{
lblFlightComponent.Text = "" + bf.flightComponent;
lblFlightComponent.Visible = true;
lblFlightComponentL.Visible = true;
}
if (bf.unitSales != 0.00m)
{
lblUnitSales.Text = "" + bf.unitSales;
lblUnitSales.Visible = true;
lblUnitSalesL.Visible = true;
}
if(bf.rentalCar!=0.00m)
{
lblCT.Visible = true;
lblRentalCar_L.Visible = true;
lblRentalCar.Visible = true;
lblRentalCar.Text = "" + bf.rentalCar;
}
if (bf.discount != 0.00m)
{
lblDiscount.Text = "" + bf.discount;
lblDiscountL.Visible = true;
lblDiscount.Visible = true;
}
if(bf.packageInclusion!="")
{
lblPackageInclusion.Text = bf.packageInclusion;
lblPackageInclusion.Visible = true;
lblPackageInclusionL.Visible = true;
}
//BF is a class object stored in a session that i put from the previous page.
Is there something wrong?
The Dispose method is not for the thing you want. Check in the docs to see what it really does.
When you want to hide a control, try setting their Visibility to false, or try removing them from their parent container control.
Conditionally setting their Visibility to true is not enough. In 99% of cases they would be visible anyways, since that's the default value for visibility. You must ensure to either set their initial Visibility to false, or add else clause that will do that.
I have this code where I compare the values of oldState object by the currentState in fluent inhibernate, what I want is to log the property that has been changed and its value,here I get the new and the old values but I waant also to get the property name.
if I reflect #event.Entity I can get all the properties and their values so is there any way to get the property name by its value.
public void OnPostUpdate(NHibernate.Event.PostUpdateEvent #event)
{
var entityToAudit = #event.Entity as IAuditable;
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AuditLog.txt");
using (StreamWriter sw = File.AppendText(path))
{
for (int i = 0; i < #event.OldState.Length; i++)
{
if (#event.OldState[i] != null)
{
if (!#event.OldState[i].Equals(#event.State[i]))
{
sw.WriteLine("the value has ben changed from " + #event.OldState[i] + " to " + #event.State[i]);
}
}
else
{
if (#event.State[i] != null)
{
sw.WriteLine("the value has ben changed from being empty to " + #event.State[i]);
}
}
}
}
}
You don't need to use System.Reflection for that. PostUpdateEvent already contains all the property names in the order you need :
var propertyName = e.Persister.PropertyNames[i];
So I have a WPF window. There are TextBoxes "Login" and "Ip Address" which are binded to "Login" and "IpAddress" properties. What I need is to save property Login into database as login#ipAddress.
I tried this, but it goes wrong:
public string Login
{
get { return _TModel.Login; }
set
{
if (value == _TModel.Login)
return;
_TModel.Login = value + "#" + IpAddress;
base.OnPropertyChanged("Login");
}
}
How can I do that? BTW I'm using NHibernate to work with the DB.
Thank you.
Replace # with "#":
public string Login
{
get { return _TModel.Login; }
set
{
if (value == _TModel.Login)
return;
value = string.Empty;
_TModel.Login = value + "#" + IpAddress;
base.OnPropertyChanged("Login");
}
}
I am trying to bind a DataGridViewComboBox to a list for hours now.
But a
"Value is not valid"-Error-Dialog is everything I get :(
From my local oracle-test-database I am fetching some data. Everything works fine but the combobox. I want the combobox to show the - sometimes - in the db chosen value and let the user change the value via the combobox.
I have a class called DtoPerson:
internal class DtoPerson
{
private String _name;
private Int32 _personRollenId;
public String Name
{
get { return _name; }
set { _name = value; }
}
public Int32 PersonRollenId
{
get { return _personRollenId; }
set { _personRollenId = value; }
}
}
I am filling a list of DtoPersons within this method:
private void CreateList()
{
DataRow[] treiberRows = _personTable.Select("ROLLE = '2'", "PERSONNAME ASC", DataViewRowState.CurrentRows);
_aufbauerListe = new List<DtoPerson>();
if (treiberRows != null && treiberRows.Length > 0)
{
foreach (DataRow row in treiberRows)
{
DtoPerson person = new DtoPerson();
//Füllen der Felder
person.Name = row["PERSONNAME"].ToString();
int persoId;
Int32.TryParse(row["PERSROLLID"].ToString(), out persoId);
person.PersonRollenIdInt = (persoId > 0) ? persoId : -1;
_aufbauerListe.Add(person);
}
}
}
´After´ loading all data, I am Binding the ComboBox to the List:
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DataSource = DaPerson.Instance.AufbauerListe;
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DisplayMember = "Name";
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).ValueMember = "PersonRollenId";
(_dgvDb.Columns["AUFBAUER"] as DataGridViewComboBoxColumn).DataPropertyName = "AUFBAUERID";
Now every time i choose a value, or there should be a prechosen value, the above mentioned error is displayed. How can I solve this?
I really need help here...
Meanwhile I found my mistake:
The OracleXE send my value as an Decimal, a type I never heard / dreamed of... ...now by changing the Id-Property to
public Decimal PersonRollenId
{
get { return _personRollenId; }
set { _personRollenId = value; }
}
everything works just fine.
It's a pitty, that DataTables don't show what kind of types they inherit...