Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Grid with XmlDataProvider and ContentControl?
    text
    copied!<p>What is wrong with <code>DataTemplate x:Key="CellTemplate"</code> <em>not</em> reaching the <code>DataContext</code> of the Grid's <code>ContentControl</code>?</p> <pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WpfApplication1.Page1"&gt; &lt;Page.Resources&gt; &lt;XmlDataProvider x:Key="xml"&gt; &lt;x:XData&gt; &lt;root xmlns=""&gt; &lt;foo a="one" /&gt; &lt;foo a="two" /&gt; &lt;foo a="three" /&gt; &lt;foo a="four" /&gt; &lt;/root&gt; &lt;/x:XData&gt; &lt;/XmlDataProvider&gt; &lt;/Page.Resources&gt; &lt;Grid DataContext="{Binding Mode=Default, Source={StaticResource xml}}"&gt; &lt;Grid.Resources&gt; &lt;DataTemplate x:Key="CellTemplate"&gt; &lt;TextBlock Foreground="AntiqueWhite" Text="{Binding Mode=Default, XPath=.}" /&gt; &lt;DataTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding XPath=.}" Value="three"&gt; &lt;Setter Property="TextBlock.FontWeight" Value="Bold" /&gt; &lt;/DataTrigger&gt; &lt;/DataTemplate.Triggers&gt; &lt;/DataTemplate&gt; &lt;/Grid.Resources&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;ContentControl Grid.Row="0" ContentTemplate="{StaticResource CellTemplate}" DataContext="{Binding Mode=Default, XPath=/root/foo[1]/@a}" /&gt; &lt;ContentControl Grid.Row="1" ContentTemplate="{StaticResource CellTemplate}" DataContext="{Binding Mode=Default, XPath=/root/foo[2]/@a}" /&gt; &lt;ContentControl Grid.Row="2" ContentTemplate="{StaticResource CellTemplate}" DataContext="{Binding Mode=Default, XPath=/root/foo[3]/@a}" /&gt; &lt;ContentControl Grid.Row="3" ContentTemplate="{StaticResource CellTemplate}" DataContext="{Binding Mode=Default, XPath=/root/foo[4]/@a}" /&gt; &lt;/Grid&gt; &lt;/Page&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload