-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scientific Notation for Numeric Data #29
Comments
<DataGrid dataGrid2D:ItemsSource.Array2D="{Binding Data2D}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding C0, StringFormat=F2}" Header="Col 1" />
<DataGridTextColumn Binding="{Binding C1, StringFormat=F2}" Header="Col 2" />
</DataGrid.Columns>
</DataGrid> ^ Seems to work, will not be much fun if the size is not fixed. An alternative is to use the <DataGrid dataGrid2D:ItemsSource.Array2D="{Binding Array2D}"
IsReadOnly="True">
<dataGrid2D:Cell.Template>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=F2}" />
</DataTemplate>
</dataGrid2D:Cell.Template>
</DataGrid> I'm not sure if |
I suppose you can set dataTemplate for cell: <DataTemplate x:Key="CellTemplate">
<TextBlock Text="{Binding Path=., StringFormat=E5}" />
</DataTemplate> dataGrid2D:Cell.Template="{StaticResource CellTemplate}" if column count is fluent |
@JohanLarsson @FoggyFinder Thank you very much for the replies. I have tried both of your solutions and then realized that I forgot to mention that I also want to edit the cells and have TwoWay binding. My 2D data can also vary in size, which makes it unfavorable to pre-define the columns. This enables me to edit the cells but doesn't update the source: <DataTemplate x:Key="dg2DCellTemplate">
<TextBox Text="{Binding Path=., StringFormat=0.000000E+00, Mode=TwoWay, BindsDirectlyToSource=True, UpdateSourceTrigger=LostFocus, NotifyOnSourceUpdated=True}" BorderBrush="{x:Null}" />
</DataTemplate>
...
<DataGrid dataGrid2D:ItemsSource.Array2D="{Binding Path=Outputs[0].Matrix, Mode=TwoWay}" ColumnWidth="*" dataGrid2D:Cell.Template="{StaticResource dg2DCellTemplate}" /> On the other hand, TwoWay binding works when I'm not using Can you please shed some light on this? Thanks. |
Normally when using dataTemplates for a DataGrid, you will use two
templates: one for displaying, one for editing. Maybe that would help? The
2D datagrid allows for this also. If I remember correctly:
dataGrid2D:Cell.Template="{StaticResource CellTemplate}"
dataGrid2D:Cell.EditingTemplate="{StaticResource CellEditingTemplate}"
…On Sat, Mar 24, 2018 at 11:50 PM, Kan Wang ***@***.***> wrote:
@JohanLarsson <https://github.com/JohanLarsson> @FoggyFinder
<https://github.com/FoggyFinder> Thank you very much for the replies.
I have tried both of your solutions and then realized that I forgot to
mention that I also want to edit the cells and have TwoWay binding.
This enables me to edit the cells but doesn't update the source:
<DataTemplate x:Key="dg2DCellTemplate">
<TextBox Text="{Binding Path=., StringFormat=0.000000E+00, Mode=TwoWay, BindsDirectlyToSource=True, UpdateSourceTrigger=LostFocus, NotifyOnSourceUpdated=True}" BorderBrush="{x:Null}" />
</DataTemplate>
Can you please shed some light on this?
Thanks.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABpzEjYEEH4sBAESKKGQcq__q3EDX28nks5ths2zgaJpZM4S5epp>
.
--
To ensure safety and privacy, this email will selfdestruct in 5 seconds.
Don't panic!
|
Looks like we have a bug. When using: <DataGrid dataGrid2D:ItemsSource.Array2D="{Binding Array2D}">
<dataGrid2D:Cell.Template>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=E1}" />
</DataTemplate>
</dataGrid2D:Cell.Template>
<dataGrid2D:Cell.EditingTemplate>
<DataTemplate>
<TextBox Text="{Binding}" />
</DataTemplate>
</dataGrid2D:Cell.EditingTemplate>
</DataGrid> It throws when entering edit mode. |
Strange! I use this all the time, never had any trouble. Though I always
bind to properties on objects in a 2D array, not directly to those items
themselves.
…On Sun, Mar 25, 2018 at 1:30 PM, Johan Larsson ***@***.***> wrote:
Looks like we have a bug. When using:
<DataGrid dataGrid2D:ItemsSource.Array2D="{Binding Array2D}">
<dataGrid2D:Cell.Template>
<DataTemplate>
<TextBlock Text="{Binding StringFormat=E1}" />
</DataTemplate>
</dataGrid2D:Cell.Template>
<dataGrid2D:Cell.EditingTemplate>
<DataTemplate>
<TextBox Text="{Binding}" />
</DataTemplate>
</dataGrid2D:Cell.EditingTemplate>
</DataGrid>
It throws when entering edit mode.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABpzEklKlgkNMkFbPFRcj84cvt1qFyUiks5th3_EgaJpZM4S5epp>
.
--
To ensure safety and privacy, this email will selfdestruct in 5 seconds.
Don't panic!
|
Hello! Can anybody help me? I wanna bind 2D int array to DataGrid, but I don't understand how to create TwoWay binding. Now I'm use this code:
Also I'm tried to add an attributes like "Mode=TwoWay, BindsDirectlyToSource=True, UpdateSourceTrigger=LostFocus, NotifyOnSourceUpdated=True" In data templates, but it's do nothing effect. Now it's allow me to entering some numbers in cells, but not save to my array. And one detail - everything work good without templates, but I need them. |
@odinsacred there is no "standard" way, but I suppose you can use converter for your collection (so it will be inner wrapper) |
@FoggyFinder Maybe we should add an |
@JohanLarsson Maybe. I was thinking about how better to handle this case, but all my options has some limitations, so I decided that simple converter is better. |
Thank you for this amazing user control. I'm currently trying to use it to display large numbers best represented in scientific notation in my project.
I have tried modifying your code by manually assigning
StringFormat
of Binding andItemStringFormatProperty
of ItemControl. But the format of the result stays the same.Can anyone please point me to the right direction on how this can be implemented?
Thanks.
The text was updated successfully, but these errors were encountered: