Expression Blend, ItemTemplate and Implicit Style

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:

Expected Output

and this is what Blend represents:

Blend rendered

<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.

+4
source share
1 answer

Blend is first written in WPF and XAML. So Blend has its own application style, and since your application also defines global styles so as not to combine them, they will apply them differently, and there is probably an error in the method they used to apply these styles.

This is my guess why this is happening. However, this does not solve the problem, but may help you find other workarounds.

+1
source

All Articles