开发者

wpf visual studio designer won't load user controls

The view below is a container for three user controls, and I started getting this error after refactoring application resources:

Error   295 Could not create an instance of type 'FilterPanel'. C:...\ProjectPickerWindow.xaml

Here is the xaml for the view:

<Window x:Class="Smack.ConstructionAdmin.WpfPresentation.Views.ProjectPicker.ProjectPickerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local ="clr-namespace:Smack.ConstructionAdmin.WpfPresentation.Views.ProjectPicker"
xmlns:res="clr-namespace:Smack.ConstructionAdmin.WpfPresentation"
    Background="{DynamicResource {x:Static res:SmackResources.WaveWindowBackground}}"
    Title="{Binding Path=DisplayName}"  FontFamily="Arial" FontSize="12" 
    SizeToContent="WidthAndHeight" MinWidth="300"
    >

<DockPanel LastChildFill="True">
    <local:FilterPanel DockPanel.Dock="Top"  DataContext="{Binding}" Padding="3" />
    <local:StatusAndButtons DockPanel.Dock="Bottom" DataContext="{Binding}" Margin="3, 7" />
    <local:Listing DataContext="{Binding}"  Margin="3, 0"/>
</DockPanel>

The app runs fine, and I can undo the refactorings, but I would prefer not to. All of the user controls display fine in their designer windows.

Can someone tell me how to get this to display in the designer?

Cheers,

Berryl

=== ADD'L INFO @ Andrew ===

Great general checklist, if not the fix yet.

1) no silent binding errors

2) the designer works great after commenting out the FilterPanel!

3) no noticeable behavior cha开发者_开发百科nge; all tests past too

4) yeah, I may have not left enough bread crumbs to nail the exact refactor but major ones were:

-- put all converters for the presentation in the own ResourceDic

-- had the FilterPanel reference generic.xaml, which has all mergedResourceDics. It referenced a specific Dic called ListingStyles.xaml, which used to have the converters

As an aside, do any tools help find Resource 'problems' (Snoop, Mole?)? Is there anything like FxCop to find bad practices??


Not yet an answer but some suggestions as there is not enough information to go on without knowing more about the app: (Posted as an answer as I thought it too long for a comment).

These designer only issues are a pain to track down as the root cause is often not specifically related to where the error arises.

This looks as if FilterPanel has a dependency on an object that doesn't yet exist. I have usually found these to be either due to not resolving resource dictionaries correctly or ValueConverter parameters not cast properly to types or initialised at Design time.

Things to try - in ascending order of speed 1) Run the app and look at the Output window to ensure there are no silent binding errors. 2) Narrow down the issue - if you comment out the line that refers to the FilterPanel does the designer work? Often the error crops up in the next line. 3) Although the app appears to run OK has this introduced different behaviours? 4) Step back through your refactorings to find the point at which the problem arose.

I have found Expression Blend to be more tolerant but not necessarily more verbose when it does fall over.

UPDATE:

If you haven't already you may need to add the ThemeInfo custom attribute to your custom controls so they can find their resources - although I think if this mechanism were not working the app would throw an Exception. Anyhow the declaration is

[assembly:ThemeInfo( //Theme specific resources, //Generic resources )]


There is a bunch of valid code/xaml that the VS2K8 designer cannot handle. A lot of them the Blend designer can handle.

If your control needs to be constructed in a special way before it can be 'used', then VS will blow up.

One VS2008 problem is controls from an abstract class. here or here which sounds like what may have happened if you are "refactoring"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜