Answer the question
In order to leave comments, you need to log in
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>
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();
}
}
}
}
<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>
Answer the question
In order to leave comments, you need to log in
In the "MainWindow.xaml" code, you need to replace "myCtrls:ShowNumberNumberControl" with "local:ShowNumberControl".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question