The oh so awesome AG_E_PARSER_BAD_PROPERTY_VALUE
I'm trying to extend the datagridcolumn a bit so I can make column widths percentage based, rather then absolute in silverlight. This way no matter what size the grid, the columns take up a specified percentage of the grid.
Anyway, this is my first step
public static class DataGridC开发者_运维问答olumnBehaviors
{
public static readonly DependencyProperty WidthPercentageProperty =
DependencyProperty.RegisterAttached("WidthPercentage", typeof(double?), typeof(DataGridColumnBehaviors),
new PropertyMetadata(null, OnWidthPercentagePropertyChanged));
public static double? GetWidthPercentage(DependencyObject d)
{
return (double?)d.GetValue(WidthPercentageProperty);
}
public static void SetWidthPercentage(DependencyObject d, double? value)
{
d.SetValue(WidthPercentageProperty, value);
}
public static void OnWidthPercentagePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
}
}
And in the XAML I'm doing
<data:DataGridTemplateColumn MinWidth="200"
dataBehaviors:DataGridColumnBehaviors.WidthPercentage="5.0"
Header="Name">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding Name, Mode=TwoWay}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
This is producing the following message at runtime
AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 85 Position: 100]
Line 85 is this:
dataBehaviors:DataGridColumnBehaviors.WidthPercentage="5.0
Any ideas?
You can't convert from a double to a double? at the CLR level like that. And you almost certainly don't want to.
Silverlight uses doubles and then uses double.NaN and double.PositiveInfinity to represent 'special' values.
精彩评论