Results 1 to 3 of 3

Thread: [RESOLVED] Build a SpotLight Control Iusse Unrecognized class

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    174

    Resolved [RESOLVED] Build a SpotLight Control Iusse Unrecognized class

    Hello,
    I'm new to WPF(coming from winform), and I'm trying to build a "spotlight control". When I try to compile I get BC30002 SpotLight:LedControl is not defined, but it actually exist.
    This is the xaml code:
    Code:
    <UserControl x:Class="StopLight"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:local="clr-namespace:SpotLight"
                 mc:Ignorable="d"
                  d:DesignHeight="46" d:DesignWidth="135">
        <UserControl.Resources>
    
            <Style TargetType="local:LedControl">
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="Margin" Value="5"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:LedControl">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
    
                                <Grid Background="Transparent" Name="grd"
                                Margin="{TemplateBinding Padding}"
                                VerticalAlignment="Stretch"
                                Width="{Binding Path=ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}">
    
                                    <Ellipse x:Name="LedBorder"
                                        Fill="{TemplateBinding Background}"
                                        Stroke="{TemplateBinding BorderBrush}"
                                        StrokeThickness="2"
                                        Stretch="Uniform"/>
    
                                    <Ellipse x:Name="CenterGlow" Stretch="Uniform">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush>
                                                <GradientStop Color="White" Offset="-0.25"/>
                                                <GradientStop Color="Transparent" Offset="0.91"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
    
                                    <Ellipse x:Name="CornerLight" Stretch="Uniform" Margin="2">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush Center="0.15 0.15" RadiusX="0.5" RadiusY="0.5">
                                                <GradientStop Color="White" Offset="0"/>
                                                <GradientStop Color="Transparent" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                </Grid>
    
                                <ContentPresenter x:Name="content" Grid.Column="1" Margin="4,0,0,0"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                RecognizesAccessKey="True"/>
    
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="true">
                                    <Setter TargetName="LedBorder" Property="Fill" Value="{Binding Path=OnColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="{Binding Path=OnColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                </Trigger>
    
                                <Trigger Property="IsChecked" Value="false">
                                    <Setter TargetName="LedBorder" Property="Fill" Value="{Binding Path=OffColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="{Binding Path=OffColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                </Trigger>
    
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter TargetName="CenterGlow" Property="Fill">
                                        <Setter.Value>
                                            <RadialGradientBrush Opacity="1">
                                                <GradientStop Color="Transparent" Offset="-0.5" />
                                                <GradientStop Color="#888" Offset="1" />
                                            </RadialGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="#888"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </UserControl.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <local:LedControl  x:Name="btnRed" OnColor="Red" IsChecked="True" Height="36" OffColor="#FF550c08" Width="36" Grid.Column="0" Click="btnRed_Click"/>
            <local:LedControl x:Name="btnYellow" OnColor="LimeGreen" IsChecked="false" Height="36" OffColor="#FF054005" Width="36" Grid.Column="2" Click="btnYellow_Click" />
            <local:LedControl x:Name="btnGreen"   OnColor="Yellow" IsChecked="false" Height="36" OffColor="#FF9BA40C"  Width="36"  Grid.Column="1" Click="btnGreen_Click"/>
    
        </Grid>
    </UserControl>

    And this is the code behind:
    Code:
    Imports LedControl
    Public Class SpotLight
        Private Sub btnRed_Click(sender As Object, e As RoutedEventArgs)
            If btnRed.cheched = False Then
                btnRed.cheched = True
                btnGreen.checked = False
                btnYellow.checked = False
            End If
        End Sub
    
    
        Private Sub btnGreen_Click(sender As Object, e As RoutedEventArgs)
            If btnGreen.cheched = False Then
                btnRed.cheched = False
                btnGreen.checked = True
                btnYellow.checked = False
            End If
        End Sub
    
        Private Sub btnYellow_Click(sender As Object, e As RoutedEventArgs)
            If btnYellow.cheched = False Then
                btnRed.cheched = False
                btnGreen.checked = False
                btnYellow.checked = True
            End If
        End Sub
    
    
    End Class
    Public Class LedControl
        Inherits CheckBox
    
        Shared Sub New()
            DefaultStyleKeyProperty.OverrideMetadata(GetType(LedControl), New FrameworkPropertyMetadata(GetType(LedControl)))
        End Sub
    
        Public Shared ReadOnly OnColorProperty As DependencyProperty = DependencyProperty.Register("OnColor", GetType(Brush), GetType(LedControl), New PropertyMetadata(Brushes.Green))
    
        Public Property OnColor As Brush
            Get
                Return CType(GetValue(OnColorProperty), Brush)
            End Get
            Set(ByVal value As Brush)
                SetValue(OnColorProperty, value)
            End Set
        End Property
    
        Public Shared ReadOnly OffColorProperty As DependencyProperty = DependencyProperty.Register("OffColor", GetType(Brush), GetType(LedControl), New PropertyMetadata(Brushes.Red))
    
        Public Property OffColor As Brush
            Get
                Return CType(GetValue(OffColorProperty), Brush)
            End Get
            Set(ByVal value As Brush)
                SetValue(OffColorProperty, value)
            End Set
        End Property
    End Class
    I did not understand why I still get this error..

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,022

    Re: Build a SpotLight Control Iusse Unrecognized class

    Quote Originally Posted by hannibal smith View Post
    Hello,
    I'm new to WPF(coming from winform), and I'm trying to build a "spotlight control". When I try to compile I get BC30002 SpotLight:LedControl is not defined, but it actually exist.
    This is the xaml code:
    Code:
    <UserControl x:Class="StopLight"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:local="clr-namespace:SpotLight"
                 mc:Ignorable="d"
                  d:DesignHeight="46" d:DesignWidth="135">
        <UserControl.Resources>
    
            <Style TargetType="local:LedControl">
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                <Setter Property="BorderBrush" Value="Black"/>
                <Setter Property="Margin" Value="5"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="local:LedControl">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
    
                                <Grid Background="Transparent" Name="grd"
                                Margin="{TemplateBinding Padding}"
                                VerticalAlignment="Stretch"
                                Width="{Binding Path=ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}">
    
                                    <Ellipse x:Name="LedBorder"
                                        Fill="{TemplateBinding Background}"
                                        Stroke="{TemplateBinding BorderBrush}"
                                        StrokeThickness="2"
                                        Stretch="Uniform"/>
    
                                    <Ellipse x:Name="CenterGlow" Stretch="Uniform">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush>
                                                <GradientStop Color="White" Offset="-0.25"/>
                                                <GradientStop Color="Transparent" Offset="0.91"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
    
                                    <Ellipse x:Name="CornerLight" Stretch="Uniform" Margin="2">
                                        <Ellipse.Fill>
                                            <RadialGradientBrush Center="0.15 0.15" RadiusX="0.5" RadiusY="0.5">
                                                <GradientStop Color="White" Offset="0"/>
                                                <GradientStop Color="Transparent" Offset="1"/>
                                            </RadialGradientBrush>
                                        </Ellipse.Fill>
                                    </Ellipse>
                                </Grid>
    
                                <ContentPresenter x:Name="content" Grid.Column="1" Margin="4,0,0,0"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                RecognizesAccessKey="True"/>
    
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="true">
                                    <Setter TargetName="LedBorder" Property="Fill" Value="{Binding Path=OnColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="{Binding Path=OnColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                </Trigger>
    
                                <Trigger Property="IsChecked" Value="false">
                                    <Setter TargetName="LedBorder" Property="Fill" Value="{Binding Path=OffColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="{Binding Path=OffColor, RelativeSource={RelativeSource TemplatedParent}}"/>
                                </Trigger>
    
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter TargetName="CenterGlow" Property="Fill">
                                        <Setter.Value>
                                            <RadialGradientBrush Opacity="1">
                                                <GradientStop Color="Transparent" Offset="-0.5" />
                                                <GradientStop Color="#888" Offset="1" />
                                            </RadialGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter TargetName="content" Property="TextElement.Foreground" Value="#888"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </UserControl.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <local:LedControl  x:Name="btnRed" OnColor="Red" IsChecked="True" Height="36" OffColor="#FF550c08" Width="36" Grid.Column="0" Click="btnRed_Click"/>
            <local:LedControl x:Name="btnYellow" OnColor="LimeGreen" IsChecked="false" Height="36" OffColor="#FF054005" Width="36" Grid.Column="2" Click="btnYellow_Click" />
            <local:LedControl x:Name="btnGreen"   OnColor="Yellow" IsChecked="false" Height="36" OffColor="#FF9BA40C"  Width="36"  Grid.Column="1" Click="btnGreen_Click"/>
    
        </Grid>
    </UserControl>

    And this is the code behind:
    Code:
    Imports LedControl
    Public Class SpotLight
        Private Sub btnRed_Click(sender As Object, e As RoutedEventArgs)
            If btnRed.cheched = False Then
                btnRed.cheched = True
                btnGreen.checked = False
                btnYellow.checked = False
            End If
        End Sub
    
    
        Private Sub btnGreen_Click(sender As Object, e As RoutedEventArgs)
            If btnGreen.cheched = False Then
                btnRed.cheched = False
                btnGreen.checked = True
                btnYellow.checked = False
            End If
        End Sub
    
        Private Sub btnYellow_Click(sender As Object, e As RoutedEventArgs)
            If btnYellow.cheched = False Then
                btnRed.cheched = False
                btnGreen.checked = False
                btnYellow.checked = True
            End If
        End Sub
    
    
    End Class
    Public Class LedControl
        Inherits CheckBox
    
        Shared Sub New()
            DefaultStyleKeyProperty.OverrideMetadata(GetType(LedControl), New FrameworkPropertyMetadata(GetType(LedControl)))
        End Sub
    
        Public Shared ReadOnly OnColorProperty As DependencyProperty = DependencyProperty.Register("OnColor", GetType(Brush), GetType(LedControl), New PropertyMetadata(Brushes.Green))
    
        Public Property OnColor As Brush
            Get
                Return CType(GetValue(OnColorProperty), Brush)
            End Get
            Set(ByVal value As Brush)
                SetValue(OnColorProperty, value)
            End Set
        End Property
    
        Public Shared ReadOnly OffColorProperty As DependencyProperty = DependencyProperty.Register("OffColor", GetType(Brush), GetType(LedControl), New PropertyMetadata(Brushes.Red))
    
        Public Property OffColor As Brush
            Get
                Return CType(GetValue(OffColorProperty), Brush)
            End Get
            Set(ByVal value As Brush)
                SetValue(OffColorProperty, value)
            End Set
        End Property
    End Class
    I did not understand why I still get this error..
    Hi, I noticed that you have syntax errrors in your code.

    Ex. <UserControl x:Class="StopLight"> in XAML but the code behind is Public Class SpotLight. And the properties of the buttons too specifically the spelling. Have you tried fixing all the syntax errors? I've experienced this before and once I fixed them, I can now access the class/user control.

    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    174

    Re: Build a SpotLight Control Iusse Unrecognized class

    Yes, thanks. I had solved last night. Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width