Ich hab im Designer irgendwie andauernd ein Problem mit meinen Controls:
Could not create an instance of type 'SearchResult'.
Das Control selbst kann ich im Designer öffnen, viel Code ist da auch ned drinnen. Kann ich irgendwo herausfinden wo der Designer ein Problem hat?
public partial class SearchResult : UserControl
{
private Type ItemType;
#region Event.ItemAction
private SearchResultActionEventHandler _ItemAction;
[Browsable(true)]
public event SearchResultActionEventHandler ItemAction
{
add
{
_ItemAction += value;
}
remove
{
_ItemAction -= value;
}
}
protected virtual void OnItemAction(SearchResultAction action, object id, object item)
{
if (_ItemAction != null)
_ItemAction(this, new SearchResultEventArgs() { Action = action, ID = id, ItemType = this.ItemType, Item = item });
}
#endregion
public SearchResult()
{
InitializeComponent();
}
public void SetResult(DataSet ds, Type displayType)
{
if (ds != null)
{
this.ItemType = displayType;
grdResult.IsReadOnly = true;
grdResult.ItemsSource = new DataView(ds.Tables[0]);
}
}
public void SetResultList<T>(List<T> lst)
{
ItemType = typeof(T);
if (lst.Count > 0)
{
ItemType = lst[0].GetType();
grdResult.IsReadOnly = true;
grdResult.ItemsSource = lst;
}
}
public void SetResultList(System.Collections.IList lst)
{
if (lst.Count > 0)
{
ItemType = lst[0].GetType();
grdResult.IsReadOnly = true;
grdResult.ItemsSource = lst;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
OnItemAction(SearchResultAction.Open, ((Button)sender).Tag, ((Button)sender).DataContext);
}
}
Hi tkrasinger,
irgendwie bin ich verwirrt. 😃
Also kann nun eine Instanz erzeugt werden oder nicht?
Denn wenn das Control im Designer komplett angezeigt wird, kann in der Regel eine Instanz erstellt werden.
Also meistens liegt es an dem fehlenden parameterlosen Konstruktor bzw. an Code innerhalb des Konstruktors, der zur Designzeit nicht ausführbar ist.
MfG
wax
Das Control SearchResult selbst kann ich im Designer öffnen. Aber in einem anderen Control in dem ich dieses Control verwende spinnt der Designer und der Fehler ist nur: Could not create an instance of type 'SearchResult'. Mehr krieg ich ned.
wie sieht der xaml header aus dieses user controls ?
Ups, sehe gerade das ich hier im WPF-Bereich bin. Und tschüss.... 😃
wie sieht der xaml header aus dieses user controls ?
<UserControl x:Class="MyProject.WPF.Controls.SearchResult"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit">
...
</UserControl>
Also meine Frage ist eigentlich viel mehr, hab ich irgendwie eine Chance mehr als die Meldung "Can not create instance" zu bekommen? Schreibt der Designer irgendwo log-Files wo ich mehr Informationen bekomme, warum er die Instanz nicht hat erstellen können?
nicht das ich wuesste - leider
diesen fehler hatte ich immer nur wenn in einem control im ctor was schief lief oder de dependency properties falsch waren (auch benutzte unter controls)
kannst du mal versuchen das toolkit control raus zu nehmen bzw aus zu kommentieren ?
evtl knallt der ctor dieses benutzten controls