datagrid binding help

602
4
06-04-2010 10:35 AM
ThaoNguyen
New Contributor II
Hi,
I got the source code of the Spatial Query sample which is a silverlight project and "converted" to WPF so that I can launch it in windows.  However, I don't see any text in my grid even though the number of rows returned is correct.  Please help!

The sample is here:
http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#SpatialQuery

When trying to convert to wpf I had to do the following:
- Changed namespace System.Windows.Controls to Microsoft.Windows.Controls.
- Change System.Windows.Controls.Primitives to Microsoft.Windows.Controls.Primitives
- Changed <slPrimitives:DataGridFrozenGrid Name="Root"> to <local:DataGridFrozenGrid Name="Root">.  I copied the source code of DataGridFrozenGrid to my local namespace because the class is not found in the namespace Microsoft.Windows.Controls.Primitives.
- Other minor changes. 
Please see the modified code in the attachment zip file.  I also attach the image how my datagrid looks like.

Thanks a lot!!  I really appreciate your time!

Thao
0 Kudos
4 Replies
DominiqueBroux
Esri Frequent Contributor
The initialization of the Binding property of the grid column is missing is the code of your DataGridTextColumn class :
        public GraphicAttributeColumn()
        {
            Binding b = new System.Windows.Data.Binding("Attributes");
            b.Converter = new DictionaryConverter();
            BindingObj = b;
            this.Binding = b; // MISSING
        }


That being said the usage of the Dictionary converter is not needed with WPF (nor with Silverlight 4.0), so instead of using your custom class, you could use the standard DataGridTextColumn class:
<slData:DataGridTextColumn  Width="80" SortMemberPath="STATE_NAME" Binding="{Binding Attributes[STATE_NAME]}" Header="State Name" />
0 Kudos
by Anonymous User
Not applicable
Original User: bbthao

I replaced this.Binding = b with BindingObj = b.
I thought that would be OK.  But you were right!! After adding this.Binding = b, the values are displayed!  Thank you so much.  You saved lots of my time!!!  I'm pretty new to wpf; therefore, I'm not sure how things are connected.
0 Kudos
ThaoNguyen
New Contributor II
The initialization of the Binding property of the grid column is missing is the code of your DataGridTextColumn class : 
        public GraphicAttributeColumn()
        {
            Binding b = new System.Windows.Data.Binding("Attributes");
            b.Converter = new DictionaryConverter();
            BindingObj = b;
            this.Binding = b; // MISSING
        }


That being said the usage of the Dictionary converter is not needed with WPF (nor with Silverlight 4.0), so instead of using your custom class, you could use the standard DataGridTextColumn class: 
<slData:DataGridTextColumn  Width="80" SortMemberPath="STATE_NAME" Binding="{Binding Attributes[STATE_NAME]}" Header="State Name" />



I also tried your suggestion, it works as well. BTW, I had to remove RowStyle="{StaticResource MyCustomRow}" in the xaml. Leaving it produces a weird grid. I don't know why.
0 Kudos
by Anonymous User
Not applicable
Original User: dbroux

Your are welcome.

The confusion is coming from the DataGridTextColumn which has a Dependency Property  called 'Binding' which has to be initialized with a Binding object.
In the C# code:
- b is referencing the binding object
- this.Binding is referencing the DP to initialize.

The XAML version is clearer.
0 Kudos