A
A
Adolf Milos2020-03-20 18:37:31
.NET
Adolf Milos, 2020-03-20 18:37:31

WPF custom XAML control insert error?

I created a special UserControl control, stuffed a Label into it, configured:

<UserControl x:Class="CustomDepProp.ShowNumberControl"
             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"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Label x:Name="numberDisplay" Height="50" Width="200" Background="LightBlue"/>
    </Grid>
</UserControl>

5e74e205e02e1558689796.png

In the code, the UserControl set the properties for the created Label
namespace CustomDepProp
{
    /// <summary>
    /// Логика взаимодействия для ShowNumberControl.xaml
    /// </summary>
    public partial class ShowNumberControl : UserControl
    {
        public ShowNumberControl()
        {
            InitializeComponent();
        }

        // Обычное свойство .NET
        private int _currNumber = 0;
        public int CurrentNumber
        {
            get => _currNumber;
            set
            {
                _currNumber = value;
                numberDisplay.Content = CurrentNumber.ToString();
            }
        }

    }
}


I'm trying to insert this element into the main window
<Window x:Class="CustomDepProp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CustomDepProp"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <StackPanel>
        <myCtrls:ShowNumberNumberControl x:Name="myShowNumberControl" CurrentNumber="100"/>
    </StackPanel>
</Window>


But errors fly out
5e74e2c8b2c62787829292.png

Tell me what the problem is.
I do everything according to the book "The C# 7 Programming Language and the .NET and .NET Core Platforms, 8th Ed. Andrew Troelsen, Philip Japix" p. 1027

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2020-03-21
@AlexanderYudakov

In the "MainWindow.xaml" code, you need to replace "myCtrls:ShowNumberNumberControl" with "local:ShowNumberControl".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question