I am having a problem with Blend not render items in an implanted DataTemplate form.
I installed a basic project to replicate the problem. Below is the Xaml + ResourceDictionary for those who have Eagle eyes to see what I am doing wrong (if any), and if you are really interested in the link to the Zipped project below.
This is what appears when the application starts:

and this is what Blend represents:

<Color x:Key="TextColor1">#FF3631C4</Color> <Style TargetType="{x:Type TextBlock}"> <Setter Property="TextWrapping" Value="NoWrap"/> <Setter Property="TextTrimming" Value="None"/> <Setter Property="Foreground"> <Setter.Value> <SolidColorBrush Color="{DynamicResource TextColor1}"/> </Setter.Value> </Setter> </Style>
<Canvas x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}"> <TextBlock Text="Textblock" Canvas.Left="44.954" Canvas.Top="49.305" /> <TextBlock Text="Textblock 2" Canvas.Left="44.954" Canvas.Top="86.284" /> <ListBox ItemsSource="{Binding Collection}" Canvas.Left="134.016" Canvas.Top="29.026" Height="154.275" Width="384.575"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Property1}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Canvas>
Full sample project (65kb) - WpfApplication2.zip
Of course, the problem can be solved by explicitly defining the style, but in my main project this can cause a little headache.
I saw some comments on other posts that Blend may have problems, but nothing concrete.
Any thoughts / suggestions?
Thanks!
Edit:
I found that if I give the style an Explicit Key, I can then create an implicit style based on Explicit, for example:
<Style x:Key="TextBlockStyle1" TargetType="{x:Type TextBlock}"> <Setter Property="TextWrapping" Value="NoWrap"/> <Setter Property="TextTrimming" Value="None"/> <Setter Property="Foreground"> <Setter.Value> <SolidColorBrush Color="{DynamicResource TextColor1}"/> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyle1}" />
This gives me the opportunity to add another implicit style as a resource in my DataTemplate:
<DataTemplate> <DataTemplate.Resources> <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockStyle1}"></Style> </DataTemplate.Resources> <TextBlock Text="{Binding Property1}" /> </DataTemplate>
This will give me the opportunity that I will need in my main project, but still does not quite answer my initial question.