I am using WPF 15.1 ... and trying to simply increase the margin of one field in my grid, referring to the instructions in the help guide https://www.infragistics.com/help/wpf/17.1/xamdatagrid-configuring-template-field.
Part of my XAML code is:
<dp:XamDataGrid x:Name="dg1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" AutoFit="true"> <dp:XamDataGrid.FieldLayoutSettings> <dp:FieldLayoutSettings AutoGenerateFields="False"/> </dp:XamDataGrid.FieldLayoutSettings> <dp:XamDataGrid.FieldLayouts> <dp:FieldLayout> <dp:FieldLayout.Fields> <dp:NumericField Name="#"/> <dp:TextField Name="Account"/> <dp:TextField Name="Instrument"/> <dp:TextField Name="Strategy"/> <dp:TextField Name="Pos"/> <dp:TemplateField Name="Qty"> <dp:TemplateField.DisplayTemplate> <DataTemplate> <TextBlock Text="{ig:TemplateEditorValueBinding}" HorizontalAlignment="Center" Margin="5,0,0,0" Foreground="Blue"/> </DataTemplate> </dp:TemplateField.DisplayTemplate> </dp:TemplateField> <dp:NumericField Name="Entry"/> <dp:NumericField Name="Exit"/> <dp:DateTimeField Name="Entry Time"/> <dp:DateTimeField Name="Exit Time"/> <dp:TextField Name="Entry Name"/> <dp:TextField Name="Exit Name"/> <dp:NumericField Name="Profit"/> <dp:NumericField Name="CNP"/> <dp:NumericField Name="Comm"/> <dp:NumericField Name="Bars"/> </dp:FieldLayout.Fields> <!--Mimic NT's (absence of) Record Selector field...--> <dp:FieldLayout.Settings> <dp:FieldLayoutSettings RecordSelectorLocation="None"/> </dp:FieldLayout.Settings> </dp:FieldLayout> </dp:XamDataGrid.FieldLayouts> <!--Mimic NT's record selection behaviour--> <dp:XamDataGrid.FieldSettings> <dp:FieldSettings CellClickAction="SelectRecord"/> </dp:XamDataGrid.FieldSettings> </dp:XamDataGrid>
I have other styles defined that enable me to get negative values displayed in red (eg Profit field)... works fine.
However, the seemingly simple task of just moving the Qty field a little to the right has me stumped... once again.
As you can see, I am attempting to achieve this by setting the margin... maybe there's a better/simpler way, I can't find it. If there is a simple way to make ALL fields have a small margin... that would be just fine too, but in my case, the Text fields seem to display fine, ie with a small left margin. Numeric fields don't.
In any case... the above DataTemplate does nothing... no margin, no blue foreground (which I only added to more easily see if ANYTHING of the template was being recognized)... but no dice. I just get a plain value, jammed right up against the left edge of the column.
Like this... Qty field
but what I would like is the Qty field like this...
Have searched the forums, tried many variations... nothing changes the display of the Qty field. Which, BTW, I do NOT need to edit... in fact I definitely do NOT want a xamNumericEditor control... just plain old display a number (but nicely ;-))
Any help appreciated.
Hello Trevor,
I created a sample using your xaml code but was unable to reproduce your problem on my side.It is possible that some other settings are affecting what you see.It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Hi Mihoku,
I also created a WPF app in VS that mirrors pretty much exactly what my add-on does. And it works... but also raises more questions... which might actually provide an ultimate answer to my issue.
In this app, I have included all of the controls in my "problem" system, you can ignore them... just focus on the Numeric fields in the grid... specially Qty, which I now manage with a Template Field.
Here's what I see:
What I do not understand is why, without any setting of HorizontalAlignment, the Qty values are in fact LEFT aligned... I have Snooped the wazoo out of this, but cannot decipher what causes this... let alone being able to control it.
Now... since my original post, it has become clear that my add-on is doing something quite weird... and I have yet to figure it out. Suffice to say, I see a different hierarchy of properties in Snoop... for something that basically has the same xaml. Importantly, the Template format is NOT triggered. Also I am getting an error that does NOT occur in my little test app...
System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=Field.Label; DataItem='CellValuePresenter' (Name=''); target element is 'CellValuePresenter' (Name=''); target property is 'AutomationId' (type 'String') System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=Record.DataItemIndex; DataItem='CellValuePresenter' (Name=''); target element is 'CellValuePresenter' (Name=''); target property is 'AutomationId' (type 'String')
So, part of my issue is clearly something screwy in my add-on setup...which I need to dig deeper into (I will be doing this tonight...)
That said... if I knew how to get ALL my Numeric fields to RIGHT align by default, like in my little test... maybe I could apply that to my real app. The alternative seems to be to create Templates for all my numerics - but that seems rather cumbersome.
8078.igTemplateTest.zip
Any help with this appreciated... again.
T.
I have created a sample that adds a style to XamDataGrid.Resources from code behind for you. In this sample, styles that target ComboBoxItem and XamComboEditor are defined in Window.Resources with x:Key. They are added to XamDataGrid.Resources at run time in MainWindow's constructor.
6114.WpfApp1.zip
OK... pretty much sorted now... many thanks to you.
My main issue is resolved... the only niggling little details are things like the fill color of the filter drop-down arrow (maybe possible to tweak... if I can get to the Path.Fill property of the element), and the color of the images shown under the "=" ComparisonOperatorSelector thing... which might be a bridge too far, as I fear it will require creating a whole new set of images. Yuk... unless they too can be managed via Fill property ??
I feel pretty stupid having tried so many things that were dead-ends... until your solution revealed how to do it right. I'd like to study up on the fundamentals, so I don't feel like I'm "driving blind"... trying to program so many things I don't really understand.
If you have any suggestions ... please let me know!
If I eventually make some money selling this thing... I owe you a beer (or three !!)
Cheers,
If you wish to customize the style of XamComboEditor, which is used in the filter cell, please take a look at the default style defined in the file below(for generic theme).
C:\Program Files (x86)\Infragistics\_product_version_\WPF\DefaultStyles\Editors\EditorsGeneric.xaml
One way to change the color of the dropdown arrow is to add the following to XamDataGrid.Resources.
------(xmlns:igEditors='infragistics.com/Editors' xmlns:PresentationOptions='schemas.microsoft.com/.../options')
<SolidColorBrush PresentationOptions:Freeze="true" x:Key="{x:Static igEditors:EditorsBrushKeys.DropdownBtnGlyphNormalForegroundFillKey}" Color="color_you_like" />-----
Thanks... that works, but how can I set this at runtime so I can customize the fill color? Maybe creating the resource in my code-behind? I already posted a query in a new thread... before I saw your answer. I'll research adding resources...
I just have 1 or 2 cosmetic things like this to sort now...so almost finished ;-)
Please take a look at the new thread for changing the color at runtime.