Reputation: 11
Problem with WPF DataTemplateSelector when using SfNavigationDrawer. My issue is to prevent DataTemplateSelector from triggering in certain cases. I have an SfNavigationDrawer with a menu, and in some cases, when I click on a specific menu, I want the DataTemplateSelector not to be applied, and instead, a submenu to be opened. Currently, I'm encountering the error "Must disconnect specified child element from current parent Visual before attaching it to a new Visual." I've tried returning `null` from the DataTemplateSelector, but it causes an error when a template is already set. Please help me understand how to correctly prevent the DataTemplateSelector from triggering in my scenario.
public class MyTemplateSelector : DataTemplateSelector
{
public DataTemplate dt1 { get; set; }
public DataTemplate dt2 { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is NavigationItem navigationItem && navigationItem.Header != null)
{
switch (navigationItem.Header.ToString())
{
case "item1":
return dt1;
case "item2":
return dt2;
default:
return null;
}
}
return null;
}
}
.................................
Upvotes: 0
Views: 43