usercontrol class not recognized

Damien.darhk

Member
Joined
Aug 13, 2021
Messages
9
Programming Experience
3-5
Hello,
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. Any advice?

xaml:
<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>


Code behind:
Imports LedControl
Public Class SpotLight
    Private Sub btnRed_Click(sender As Object, e As RoutedEventArgs)
        If btnSpostaRed.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
 
Back
Top