Why can't I enable ContentControl ContentTemplateSelector in design mode?
(While working, it works)
Constructor (VS2010) shows an exception:
System.Reflection.TargetInvocationException The exception was caused by the target call.
and
The System.NullReferenceException reference object is not set to an instance of the object.
XAML:
<Window.Resources>
<DataTemplate x:Key="Temp1">
<TextBox TextWrapping="Wrap" Text="1" Height="20" Width="Auto"/>
</DataTemplate>
<local:TemplateSelector x:Key="mySelector"/>
<Grid>
<ContentControl ContentTemplateSelector="{StaticResource mySelector}">
<ContentControl.Content>
1
</ContentControl.Content>
</ContentControl>
</Grid>
</Window.Resources>
WITH#:
public class TemplateSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
Window win = Application.Current.MainWindow;
return win.FindResource("Temp1") as DataTemplate;
}
}
source
share