Not sure how much it matters, but I am using devexpress grid and defining a celltemplate for one of the columns. The issue is that when I bind with a "slidercontrol" it works, but when I bind to a UserControl of my own making, the binding doesn't work. The UserControl binds properly... I use it elsewhere in the code. It just doesn't work in this context, and I'm wondering why? Thanks.
This binding works:
<dxg:GridColumn FieldName="SetupRating" Header="Setup Rating" AllowFocus="True" AllowEditing="True">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Slider Value="{Binding RowData.Row.SetupRating}" Minimum="0" Maximum="3" />
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
This binding does not work:
<dxg:GridColumn FieldName="SetupRating" Header="Setup Rating" AllowFocus="True" AllowEditing="True">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<wpf:RatingControl RatingValue="{Binding RowData.Row.SetupRating}" MaxRating="3" />
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
EDIT: PLEASE DO NOT SUGGEST THAT wpf:RatingControl IS BROKEN. IT IS A PROVEN USER CONTROL THAT IS WORKING IN MANY OTHER DATA BINDING SCENARIOS. IF THERE IS ANYTHING WRONG WITH IT, IT WOULD HAVE TO BE SOMETHING OBSCURE THAT ONLY IMPACTS THE WAY I'M BINDING WITHIN THIS DATATEMPLATE. THANK YOU.
Here's how I define the dependency property in my rating control:
public static readonly DependencyProperty RatingValueProperty =
DependencyProperty.Register("RatingValue", typeof(int), typeof(RatingControl),
new FrameworkPropertyMetadata(0,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
RatingValueChanged));
public int RatingValue
{
get
{
return AdjustRatingValue((int)GetValue(RatingValueProperty), MaxRating);
}
set
{
SetValue(RatingValueProperty, AdjustRatingValue(value, MaxRating));
}
}
private static int AdjustRatingValue(int value, int maxValue)
{
if (value < 0)
return 0;
else if (value > maxValue)
return maxValue;
else
return value;
}
private static void RatingValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
RatingControl parent = sender as RatingControl;
int numberOfButtonsToHighlight = AdjustRatingValue((int)e.NewValue, parent.MaxRating);
SelectStars(numberOfButtonsToHighlight, parent.StarValues);
}