2

I have a base class like that in the project A

namespace WpfApplication1
{
    /// <summary>
    /// Interaktionslogik für Layer.xaml
    /// </summary>
    public partial class Layer
    {
        public Layer()
        {
            InitializeComponent();
        }
    }
}

with this xaml (in my project it has a complex tooltip, but for simplicity I changed it to a TextBlock)

<Canvas x:Class="WpfApplication1.Layer"
             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="300" d:DesignWidth="300">
    <Canvas.ToolTip>
        <TextBlock Text="ToolTip"/>
    </Canvas.ToolTip>
</Canvas>

For testing purpose I want to derive from that in my TestAssembly

using WpfApplication1;

namespace WpfApplication2
{
    public class TestingLayer : Layer
    {
    }
}

But when I start I get the the

The component `TestingLayer` does not have a resource identified by the URI `/WpfApplication1;component/layer.xaml`

I already googled and found some threads related to that problem, but with some differences:

This one suggests to make a wrapper around TestingLayer but unfortunately this doesn't work for me because I want to get access to some protected funtions (especially to OnRender whose access I can't modify). Furthermore the OP wants a derived control with xaml, and this is a big difference to my needs, because my derived class has no xaml. This difference also applies to these threads

Since the derivation works when I create TestingLayer in my project A I think there is just a problem in the URI. But I don't know how to solve it.

To sum it up: How to derive a c# class with only a cs file from a control (with xaml) from another assembly?

Community
  • 1
  • 1
Rico-E
  • 1,806
  • 2
  • 28
  • 47
  • Controls are suitable for aggregation, not for inheritance. If you mean unit testing, then you shouldn't do this. Actually, I can't imagine unit test for `OnRender` (which either renders content correctly, or incorrectly). – Dennis Jun 18 '15 at 08:08
  • Thank you for your comment. To help your imagination about a unit test for `OnRender` look at this post of mine http://stackoverflow.com/questions/29622996/unit-testing-custom-onrender-method?lq=1 – Rico-E Jun 18 '15 at 08:11
  • Sorry, but this looks like over-using of unit testing, and WPF infrastructure just confirms this. – Dennis Jun 18 '15 at 08:19
  • @Dennis: is your last comment about this question or about the thread I linked? But nevertheless, nor does it answer my question neither does it contribute the my question (which was how to derive from a control in another assembly). This question isn't about the right usage of unit-testing. – Rico-E Jun 18 '15 at 08:24
  • I think this has already been asked here: http://stackoverflow.com/questions/10503232/wpf-can-i-inherit-a-usercontrol-but-provide-no-xaml – o_weisman Jun 18 '15 at 08:55
  • Also here: http://stackoverflow.com/questions/3982191/wpf-usercontrol-inheritance?rq=1 where the accepted answer might be helpful to you. – o_weisman Jun 18 '15 at 09:07
  • @o_weisman: there is the same difference as the one I pointed out in my question: **My derived control (`TestingLayer`) has no xaml**. – Rico-E Jun 18 '15 at 09:22
  • As far as I can tell, the last suggestion I gave you has a xaml file only for the base class, but I could be wrong – o_weisman Jun 18 '15 at 10:39
  • @o_weisman: the xaml quoted in the answer (which begins with ` – Rico-E Jun 18 '15 at 12:01

0 Answers0