C
C#4mo ago
linuscoro

✅ Problems adding usercontrol

I'm trying to add a usercontrol to a window. In the window I added the local reference liek this:
cs xmlns:local="clr-namespace:PrototipServer.Controls"
cs xmlns:local="clr-namespace:PrototipServer.Controls"
` And i have use it like this:
cs <local:DataGridAlarmes x:Name="gd_Alarmes" estacioSeleccionada="gd_AlarmesSelectionChanged" Visibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,10,5" Grid.Column="2" Grid.Row="2"/>
cs <local:DataGridAlarmes x:Name="gd_Alarmes" estacioSeleccionada="gd_AlarmesSelectionChanged" Visibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,10,5" Grid.Column="2" Grid.Row="2"/>
My usercontrol is inside a folder called controls inside the project. Does anyone know why it's not working?
35 Replies
linuscoro
linuscoroOP4mo ago
The userControl is defined like this:
namespace PrototipServer.Controls
{
/// <summary>
/// Lógica de interacción para DataGridAlarmes.xaml
/// </summary>
public partial class DataGridAlarmes : UserControl
{


public DataGridAlarmes()
{
InitializeComponent();
}
namespace PrototipServer.Controls
{
/// <summary>
/// Lógica de interacción para DataGridAlarmes.xaml
/// </summary>
public partial class DataGridAlarmes : UserControl
{


public DataGridAlarmes()
{
InitializeComponent();
}
`
<UserControl x:Class="PrototipServer.Controls.DataGridAlarmes"
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:PrototipServer.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl x:Class="PrototipServer.Controls.DataGridAlarmes"
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:PrototipServer.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
`
qqdev
qqdev4mo ago
To help you to get any answers: What is the actual error you are getting?
linuscoro
linuscoroOP4mo ago
Error XDG0008 El nombre "DataGridAlarmes" no existe en el espacio de nombres "clr-namespace:PrototipServer.Controls". The name"DataGridAlarmes" dosn't exists in the namespace ...
qqdev
qqdev4mo ago
It says that the type does not exist in that namespace Yeah
linuscoro
linuscoroOP4mo ago
No description
linuscoro
linuscoroOP4mo ago
As you can see it's there
qqdev
qqdev4mo ago
Are you using the control in the same project?
linuscoro
linuscoroOP4mo ago
yes
qqdev
qqdev4mo ago
Or in a different one? Okay
linuscoro
linuscoroOP4mo ago
i'm trying to use it in a window called Manteniment
linuscoro
linuscoroOP4mo ago
No description
linuscoro
linuscoroOP4mo ago
and then i'm using it like this:
cs <controls:DataGridAlarmes x:Name="gd_Alarmes" Visibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,10,5" Grid.Column="2" Grid.Row="2"/>
cs <controls:DataGridAlarmes x:Name="gd_Alarmes" Visibility="Hidden" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,10,5" Grid.Column="2" Grid.Row="2"/>
`
qqdev
qqdev4mo ago
Does not look wrong to me Did you try rebuilding the project?
linuscoro
linuscoroOP4mo ago
Yes. and also clean it and it gives me the same error all the time
qqdev
qqdev4mo ago
Hm, no clue then You could try to come up with a minimal example Create a new project + window + user control And replicate it If it works -> You are missing something If it does not work -> We have to take a closer look
linuscoro
linuscoroOP4mo ago
Okey ty, i will try it now
qqdev
qqdev4mo ago
One more thing Did you also check the cs file of that user control? Make sure the namespace is correct there too
qqdev
qqdev4mo ago
No description
qqdev
qqdev4mo ago
Click the little arrow next to the xaml file Everything has to match to make this work
linuscoro
linuscoroOP4mo ago
Yes i have check it. Also i created a new project with a blank usercontrol inside a folder called controls and then add it to the main window and im getting the same error. So i guess i'm doing something wrong when adding the usercontrol
qqdev
qqdev4mo ago
Let me try it quickly
linuscoro
linuscoroOP4mo ago
okey
qqdev
qqdev4mo ago
Works for me ;D Can you share the contents of the files?
linuscoro
linuscoroOP4mo ago
😦
qqdev
qqdev4mo ago
$codegif
linuscoro
linuscoroOP4mo ago
yes should i pass you the new project or the one i was working on?
qqdev
qqdev4mo ago
The new one which is also not working Not as a download or zip tho Just paste it
linuscoro
linuscoroOP4mo ago
yes yes i know
<UserControl x:Class="WpfApp2.controls.DataGridProva"
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:WpfApp2.controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>

</Grid>
</UserControl>
<UserControl x:Class="WpfApp2.controls.DataGridProva"
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:WpfApp2.controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>

</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp2.controls
{
/// <summary>
/// Lógica de interacción para DataGridProva.xaml
/// </summary>
public partial class DataGridProva : UserControl
{
public DataGridProva()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp2.controls
{
/// <summary>
/// Lógica de interacción para DataGridProva.xaml
/// </summary>
public partial class DataGridProva : UserControl
{
public DataGridProva()
{
InitializeComponent();
}
}
}
<Window x:Class="WpfApp2.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:WpfApp2"
xmlns:controladors="clr-namespace:WpfApp2.controls"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<controladors:DataGridProva/>
</Grid>
</Window>
<Window x:Class="WpfApp2.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:WpfApp2"
xmlns:controladors="clr-namespace:WpfApp2.controls"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<controladors:DataGridProva/>
</Grid>
</Window>
Now i rebuild the solution and it works but not in the other one
qqdev
qqdev4mo ago
Something is wrong in the other one then
linuscoro
linuscoroOP4mo ago
yes i will check it now. Ty for the help
qqdev
qqdev4mo ago
You are welcome! You can try adding a new namespace Just for testing With a dummy user control
linuscoro
linuscoroOP4mo ago
i will create the usercontrol again Wow. Crazy how idiot I am. I was rebuilding without removing the errors...
qqdev
qqdev4mo ago
hehe $close
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server