简体   繁体   中英

How do I find the matching partial-class in C# & Visual Studio 2010 in a XAML file?

I have an app created with a third-party MVVM framework. I have a bunch of Views that will be essentially the same, so I want to inject a custom class in between my Views and the original framework View base as a new base. But when I do so I get the error, "Partial declarations of must not specify different base classes."

So ideally I'd like to change the other partial to use my newly injected custom base class as its base. But I can't find it anywhere. F12 only brings up my code behind, where the error is being generated once I change the base to my new base, and the XAML file, which has no reference to the original base.

Where is the other partial class? How do I find it? Or am I maybe just going about creating my own base class for a XAML file completely wrong in the first place?

I had the same problem when I renamed my Silverlight project's namespace and I got the "Cannot resolve symbol ' Initialize Component '" in my xaml codebehind file:

  1. Open the xaml codebehind .cs file where you're having the issue;
  2. go to View-->Class View , which will open the Class View explorer;
  3. in my case, i needed to drill into the namespace that had to be changed,
  4. then I clicked on the partial class at issue,
  5. then below in a second panel appeared the broken InitializeComponent method;
  6. double-click on that and the partial class will open with a .gics extension.

This is likely the XAML itself -

The first line of the XAML (the first keyword) defines the type on which you're based (ie: <Window or <UserControl ). That will likely need to be changed to your base class, as well as the code behind file.

If I understand your question correctly, this is a similar problem to one I've had before.

Your problem may be that the XAML file is declariing your control as a UserControl :

<UserControl x:Class="Your.ExtendedControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- other stuff goes here. -->
</UserControl>

The above may be what is causing the error. The XAML file needs to use the proper base class as the element tag, like so:

<YourNamespace:YourBaseClass x:Class="Your.ExtendedControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:YourNamespace="clr-namespace:Your.Project.Namespace">
    <!-- other stuff goes here -->
</YourNamespace:YourBaseClass>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM