数据模板的重用
我的 Treelistview 控件中的不同单元格有两个 DataTemplate。 模板有 90% 相似。 如何重用相同的 Xaml ?
<DataTemplate x:Key="@names">
<TextBlock Name="txt" Text="{Binding Names}" Style="{DynamicResource @BasicTextBlockStyle}"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border},AncestorLevel=1}, Path=BorderBrush,Mode=OneWay}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="True">
<Setter Property="Style" Value="{DynamicResource @HeaderTextBlockStyle}" TargetName="txt" />
</DataTrigger>
<DataTrigger Binding="{Binding IsScoped}" Value="True">
<Setter Property="Style" Value="{DynamicResource @RootElementTextBlockStyle}" TargetName="txt" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate x:Key="@Ages">
<TextBlock Name="txt" Text="{Binding Age}" Style="{DynamicResource @BasicTextBlockStyle}"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border},AncestorLevel=1}, Path=BorderBrush,Mode=OneWay}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="True">
<Setter Property="Style" Value="{DynamicResource @HeaderTextBlockStyle}" TargetName="txt" />
</DataTrigger>
<DataTrigger Binding="{Binding IsScoped}" Value="True">
<Setter Property="Style" Value="{DynamicResource @RootElementTextBlockStyle}" TargetName="txt" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
I have two DataTemplates for different cells in my Treelistview control.
the templates are 90% similar.
How can I reuse the identical Xaml ?
<DataTemplate x:Key="@names">
<TextBlock Name="txt" Text="{Binding Names}" Style="{DynamicResource @BasicTextBlockStyle}"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border},AncestorLevel=1}, Path=BorderBrush,Mode=OneWay}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="True">
<Setter Property="Style" Value="{DynamicResource @HeaderTextBlockStyle}" TargetName="txt" />
</DataTrigger>
<DataTrigger Binding="{Binding IsScoped}" Value="True">
<Setter Property="Style" Value="{DynamicResource @RootElementTextBlockStyle}" TargetName="txt" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate x:Key="@Ages">
<TextBlock Name="txt" Text="{Binding Age}" Style="{DynamicResource @BasicTextBlockStyle}"
Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border},AncestorLevel=1}, Path=BorderBrush,Mode=OneWay}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsVisible}" Value="True">
<Setter Property="Style" Value="{DynamicResource @HeaderTextBlockStyle}" TargetName="txt" />
</DataTrigger>
<DataTrigger Binding="{Binding IsScoped}" Value="True">
<Setter Property="Style" Value="{DynamicResource @RootElementTextBlockStyle}" TargetName="txt" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试做这样的事情:
You can try doing something like this: