I've been battling this issue for a while now and seem not to be able to come up with a concrete workaround - I have a TextBox which is bound to a decimal, and the binding has UpdateSourceTrigger set to PropertyChanged and is so by necessity (LostFocus won't work well in this case). The default behavior while I'm sure is somehow explainable, is not acceptable for my purposes, so I've tried the following StringFormat, which I had thought remedied the issue, but only partially and am now looking for something more concrete. My originaly fix was to add a string format to the binding...in my case it was
StringFormat={0:#.#####}
so when typing something like .12345 or 1.5 the solution works great, however if I type .01234, as soon as I hit the zero key, it removes the decimal I had just typed...which for obvious reasons would be disasterous in terms of data entry. I'm hoping that my familiarity with string formatting is just lacking. Wost case scenario I'll have my exposed property be a string and the setter and getter just convert to decimal, but that seems like a hacky solution.
Thanks!
Aj
I came across this because Im seeing the same issue with a .Net 4.6.2 build. I needed to enter an exchange rate, e.g. 1.15 and found it was ending up as 115 with the decimal removed. My workaround was to bind to a string property that maintained it's own string value while input e.g. 1, 1., 1.1, 1.15. But with each input attempted to update the underlying numeric property inside a Try Catch. It's far from elegant, but works for my needs.
You have two simple choices to achieve what you want:
Try typing a '0' first... you can enter '0.01234' without issue.
Use StringFormat={}{0:0.00000} instead... then you can enter '.01234' without issue.
Related
Is there an easy way to update a field on a get of a get_or_create?
I have a class ItemCategory and I want to either create a new entry or get the already created entry and update a field (update_date).
What I do is:
item,created= ItemCategory.get_or_create(cat=cat_id,item=item_id)
if created == True:
print "created"
else:
item.update_date = datetime.now
item.somethingelse = 'aaa'
item.save()
This works for a while in my loop. But after 50-100 get/create it crashes:
peewee.InterfaceError: Error binding parameter 4 - probably unsupported type.
Maybe I should use upsert(), I tried but wasn't able to get anything working. Also it's not probably the best solution, since it makes a replace of the whole row instead of just a field.
I like peewee, it's very easy and fast to use, but I can't find many full examples and that's a pity
Newbie mistake
item.update_date = datetime.now()
I am not 100% sure this is the only answer though. I modified my code so many times that it might be also something else.
Regarding my question about create_or_update , I've done this:
try:
Item.create(...)
except IntegrityError:
Item.update(...)
peewee is really great, I wonder why no one ever asked for a create_or_update.
I'm creating a custom directive that I want to use to display the value of a field and an optional suffix (expected for units and such). Note that my example is shortened to stay concise.
My template looks something like
<div class="my-value">{{boundValue}}{{boundSuffix}}</div>
For the value, I'm using a two-way binding (=) and for the suffix, I'm using a string binding (&).
It worked great when I bound ° into the suffix to display a temperature, but when I tried to bind in meters (note, there's a leading space - I don't want it pushed up against the number) the leading space seems to get trimmed and my result ends up looking like 123meters.
Using the chrome developer tools, I added a link function and inspected the directive's scope. By the time it reaches the link function, boundSuffix has already been trimmed. It seems like Angular is pulling some shenanigans on my behind the hood. Is there any way for me to avoid this trimming?
It's better to use angular filters to solve your problem. Filters allow to format your output as currency or as UPPERCASE (for example). Try to look here for more info. And here is working example
I am trying to globalize a simple WPF app. In several questions and/or answers on SO I see one of the following two settings on the binding:
StringFormat=C
StringFormat='{}{0:C}'
What is the difference between these? Are there certain conditions where you would use one over the other?
My understanding is that there is no difference, one is just shorthand and the other explicit. The only condition I can think of where being explicit is beneficial is when you want more control over the format. For example:
StringFormat=Total: {0:C}
Other than that, I'd say keep it simple; XAML is already verbose and shorthand syntax is welcome.
Maybe read up string formatting?
http://msdn.microsoft.com/en-us/library/dd465121.aspx
You can use {0:C} in a format string where you are filling in a value:
decimal value = 123.456;
Console.WriteLine("Your account balance is {0:C2}.", value);
while, you use the C as a plain format:
Console.WriteLine(("Your account balance is " + decimal.Parse("24.3200").ToString("C"));
they are functionally equivalent as far as the output. It's just a different way to format the data based on the context of how your using it.
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#CFormatString
Viewing/Searching java arrays and collections in the Eclipse Java debugger is tedious and time-consuming.
I tried this promising plugin (in alpha as of Aug 2012)
http://www.cvast.tuwien.ac.at/projects/visualdebugging/ArrayExplorer
But it freezes Eclipse for simple arrays beyond a few hundred elements.
I do use Detail formatters, but that still needs clicking on each element to see the values.
Are there any better ways to view this array/collection data?
Use the 'Expressions' tab.
There you can type in any number of expressions and have them evaluated in the current scope.
ie: collection.size(), collection.getValueAt(i), ect...
Eclipse > Preferences > Java > Debug >Detail Formatter
This may be close to what you are looking for. It is another tedious work to setup but once done you can see the value of objects in Expressions window.
Here is link to start
override toString method of your class and you will be able to see what you want to see. i'm attaching example to show you exactly that.
Even though i could not find a way to see them in nice table/array, i found a halfway workaround.
The solution is to define a static method in a throwaway class that takes the array as input and returns a string of concatenated values that one wants to quickly glance at. it could include the array index and newlines to view results formatted nicely. It can be fine tuned to print out only certain array indices to reduce clutter.
This static method can then be used in the watch area.
so I am trying to assign a number to a variable that is dynically generated from a binded array...when i try and assign it and trace it out nothing happens, which means I am obviously doing something wrong but I am not sure? just for fun i decided to bind the data to a label like so...
<s:Label text="{this.dd.selectedViews.length}"/>
and that work and updated properly, but when running in debug mode i got this warning...
warning: unable to bind to property 'length' on class 'Array' (class is not an IEventDispatcher)
so what would be the best method of assigning the array to a variable to use throughout my application
thanks in advance for any help
I'm not really sure what you are asking here, but maybe this will help you out. As your error message says, the Array class is not an IEventDispatcher. What that means is that if you try to use a plain old Array as the source of a data-binding expression, it generally is not going to work.
If you need to bind to an array, you can try using a different class such as ArrayCollection, which supports data binding.