0
무엇이 잘못 되었습니까 DataTemplate x:Key="CellTemplate"
아니요에 도달하면 ContentControl
의 DataContext
에 도달합니까?XmlDataProvider 및 ContentControl이 포함 된 WPF Grid?
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.Page1">
<Page.Resources>
<XmlDataProvider x:Key="xml">
<x:XData>
<root xmlns="">
<foo a="one" />
<foo a="two" />
<foo a="three" />
<foo a="four" />
</root>
</x:XData>
</XmlDataProvider>
</Page.Resources>
<Grid DataContext="{Binding Mode=Default, Source={StaticResource xml}}">
<Grid.Resources>
<DataTemplate x:Key="CellTemplate">
<TextBlock Foreground="AntiqueWhite"
Text="{Binding Mode=Default, XPath=.}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding XPath=.}" Value="three">
<Setter Property="TextBlock.FontWeight" Value="Bold" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0"
ContentTemplate="{StaticResource CellTemplate}"
DataContext="{Binding Mode=Default, XPath=/root/foo[1]/@a}" />
<ContentControl Grid.Row="1"
ContentTemplate="{StaticResource CellTemplate}"
DataContext="{Binding Mode=Default, XPath=/root/foo[2]/@a}" />
<ContentControl Grid.Row="2"
ContentTemplate="{StaticResource CellTemplate}"
DataContext="{Binding Mode=Default, XPath=/root/foo[3]/@a}" />
<ContentControl Grid.Row="3"
ContentTemplate="{StaticResource CellTemplate}"
DataContext="{Binding Mode=Default, XPath=/root/foo[4]/@a}" />
</Grid>
</Page>
이는 효과가 없습니다. – rasx
당신은 그것을 얻었다! ... 그리고 극단적 인 경우에,'ContentControl' 대신에, 나는 사용자 컨트롤을 고려할 것입니다 ... – rasx