ColorGallery Problem (System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=XXX); target property)

Jan 23, 2011 at 1:51 AM

Hi

I have the following errors in the immediate window when I click on the ColorGallery drop-down button:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=6853301); target property is 'Color' (type 'Color')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=10476039); target property is 'Color' (type 'Color')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=44478183); target property is 'Color' (type 'Color')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'SolidColorBrush' (HashCode=17956189); target property is 'Color' (type 'Color')

The XAML for the ColorGallery drop-down button ias as follows:

<Fluent:DropDownButton x:Name="ddbBackgroundColor" Size="Small">
                            <Fluent:DropDownButton.ToolTip>
                                <Fluent:ScreenTip Title="Background Color" Text="Change the background color."/>
                            </Fluent:DropDownButton.ToolTip>
                            <Fluent:DropDownButton.Icon>
                                <Grid Width="16" Height="16">
                                    <Image Source="Images\BackgroundColorPicker.png"/>
                                    <Border BorderThickness="0.5" BorderBrush="LightGray" VerticalAlignment="Bottom" Height="5">
                                        <Border.Background>
                                            <SolidColorBrush Color="{Binding ElementName=glyBackgroundColor, Path=SelectedColor, FallbackValue=White}" />
                                        </Border.Background>
                                    </Border>
                                </Grid>
                            </Fluent:DropDownButton.Icon>
                            <Fluent:ColorGallery x:Name="glyBackgroundColor" SelectedColor="White"  Mode="StandardColors" IsAutomaticColorButtonVisible="False" IsNoColorButtonVisible="False"/>
                        </Fluent:DropDownButton>

The XAML of the text box which has its background color bound to the ColorGallery's selected color is as follows:

<TextBox x:Name="txtMain"
         Grid.Row="1" 
         AcceptsReturn="True" 
         AcceptsTab="True" 
         HorizontalScrollBarVisibility="Auto" 
         VerticalScrollBarVisibility="Auto" 
         AutoWordSelection="True" 
         SpellCheck.IsEnabled="True" 
         Background="{Binding ElementName=glyBackgroundColor, Path=SelectedColor, FallbackValue=White, Converter={StaticResource ColorToSolidColorBrushValueConverterMain}}">
</TextBox>
                 
And finally this is the code for the color to SolidColorBrush converter:
Public Class ColorToSolidColorBrushValueConverter
    Implements IValueConverter
    Private Shared _converter As ColorToSolidColorBrushValueConverter = Nothing

    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value Is Nothing Then
            Return Nothing
        End If         
        If TypeOf value Is Color Then
            Dim color As Color = DirectCast(value, Color)
            Return New SolidColorBrush(color)
        End If
        Dim type As Type = value.[GetType]()
        Throw New InvalidOperationException("Unsupported type [" + type.Name & "]")
    End Function
    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack           
        Throw New NotImplementedException()
    End Function
End Class
Which just to remind you, throws the errors listed at the top of the post...
I would really appreciate if you can help me.
Thank you in advance!
Rayner Lim