none
DataGridColumn Header Binding Design-Time Problems on Custom Controls

    General discussion

  • Hello,

    I am working in a Business Application Template-based Silverlight 4 application where I have to localize labels.

    The strategy for localization I am using was suggested by PaulSmrz in 2010 on this thred: http://social.msdn.microsoft.com/Forums/en-US/silverlightarchieve/thread/d90d0cc1-7fd2-4a30-8a74-6ba58f5f24da//1

    This have worked fine, if it were not for the problem I am experiencing while using custom controls. Before talking to the custom control, it is important to know that I have a minor problem since the begining with DataGrid columns. When I bound its header to the localized resource, I have design-time errors on Blend and Visual Studio. Take this DataGrid and an example:

    <sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding RepositoryData.View}" x:Name="repositoryPieceGroupDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected">
                                            <sdk:DataGrid.Columns>
                                            	<sdk:DataGridTextColumn x:Name="widthColumn" Binding="{Binding WidthString}" Header="{StaticResource Width}" Width="SizeToHeader" />
                                            	<sdk:DataGridTextColumn x:Name="lengthColumn" Binding="{Binding LengthString}" Header="{StaticResource Length}" Width="SizeToHeader" />
                                            	<sdk:DataGridTextColumn x:Name="quantityColumn" Binding="{Binding quantity}" Header="{StaticResource Quantity}" Width="SizeToHeader" />
                                            	<sdk:DataGridCheckBoxColumn x:Name="useColumn" Binding="{Binding use}" Header="{StaticResource Use}" Width="SizeToHeader" />
                                            </sdk:DataGrid.Columns>
                                        </sdk:DataGrid>

    With this use of header binding I get design-time errors like: "The resource "Width" could not be resolved". At run time everything goes fine. This is because at App.xaml.cs constructor we have:

    var properties = from property in typeof(ApplicationStrings).GetProperties()
                                 where property.PropertyType == typeof(string)
                                 select property;
    
                foreach (PropertyInfo property in properties)
                {
                    string value = (string)property.GetValue(null, null);
                    App.Current.Resources.Add(property.Name, value);
                }

     Backing to my major problem, now I have created a custom control that have a DataGrid also. The same problem occurs, but the issue is that every page I use this control cannot be shown anymore at design-time (Visual Studio and Blend) and it is hard to keep going like this.

    any suggestions on how to fix that?

    Thank you,

    Igor.

     

    Thursday, May 03, 2012 10:22 AM

All replies