Reputation: 1759
I'm making a WPF CustomControlLibrary with CustomControls which inherit from standard controls like Label, TextBox etc. When i try to make another CustomControl which inherit from TextBlock, i get strange errors. It seems to be that a CustomControl can't inherit from the TextBlock.
But why?
Thanks in advance!
Upvotes: 0
Views: 618
Reputation: 27350
I have just created custom control inherited from TextBlock:
using System.Windows.Controls;
namespace WpfApplication1
{
public class CustomTextBlock : TextBlock
{
}
}
and used it within the same project:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1">
<Grid>
<local:CustomTextBlock Text="Hello" />
</Grid>
</Window>
So the anser is:
however, in order t use it in xaml, you have to compile the project first. There may be other errors in your code that prevents the project to compile and therefore you may be getting also errors like
The type 'local:CustomTextBlock' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built
or simmilar error:
The name "CustomTextBlock" does not exist in the namespace "clr-namespace:WpfApplication1".
Once you fix the other errors, these will disappear as well.
Upvotes: 0