This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is this a good (fast?) way of defining a column that is justified to the right?
My DataGrid has many rows/columns and I don't want to slow down the loading of data (assignment of ItemsSource) |
|
|
Hello Our data grid provides some right aligned numeric editors that you may want to enable. (These are not yet enabled by default because they were added recently, not in a major version). To use our right aligned numeric editors, add this code to the DataGrid tag:
These lines of code tell the data grid that ALL integer and double cells should use the IntegerEditor and NumericEditor respectively. These editor keys affect both display mode and edit mode, so the value will always be right aligned. These editors also use our IntegerTextBox and NumericTextBox controls rather than WPF TextBox controls which make numeric editing convenient for the user. If this is not of interest to you (you don't want to apply this to ALL numeric cells, or you are fine with using a TextBox instead), then the data template you posted will be fine. Our data grid uses virtualization which means that it only applies templates to cells within the viewport. One thing I should point out however is that using DisplayMemberBinding doesn't have great performance. (Bindings in WPF generally can slow things down, especially when overused). Although the virtualization helps with this, there can be a noticeable lag when loading and scrolling if the viewport is quite large. If you don't find any performance issues with the DataGrid in your application, then you don't need to worry about this next part. DisplayMemberBinding is great if you need to use a converter, string format, WPF error validation or you have a complex property path you need to bind to. If however you are simply binding to a property directly on the data item (Like in the code you posted), you do not need to use the DisplayMemberBinding. Instead, set the PropertyName property of the DataGridColumn to be the name of the property you want the column to use. (In your case "PandL"). This will cause the column to use property descriptors directly to get and set the property value. This has better performance, and will still update the display if the property changes. Jason Fauchelle |
|
|
Great to know thanks. Now, how do use PropertyName together with DisplayTemplate? Because a DisplayTemplate needs to have the binding.... |
|
|
Hello Nestor Yes, the DisplayTemplate needs to have its own binding like in the code you posted. Setting the PropertyName will map the column to the property on your model objects. This is useful for features like sorting and grouping, so the column knows what property it's dealing with. There is no choice but to use the binding in the display template. But to use PropertyName instead of DisplayMemberBinding on the column tag improves the performance because now there are less bindings being used. Did you have problems when changing from using DisplayMemberBinding to PropertyName? |
|
|
So what you are saying is that this would be the fastest xaml:
i.e. using PropertyName at the DataGridColumn level, and using {Binding Pnl} in my DisplayTemplate. The DisplayTempate is necessary here because Im applying StringFormat as well as Horizontallignment="Right" and TextTrimming="CharacterEllipsis" |
|
|
Yes, that is all correct. |
|
|
Great. Thank you! |
|