简体   繁体   English

将datatemplate应用于自定义对象?

[英]Apply datatemplate to custom object?

Assuming I have a class derived from Shape. 假设我有一个从Shape派生的类。 I'm looking for way how to implement support for binding it with datatemplate. 我正在寻找一种方法来实现对与datatemplate绑定的支持。 A datatemplate looking something like this: 一个数据模板看起来像这样:

<DataTemplate>    
  <Grid x:Name="grid">
        <Path x:Name="path" Data="F1 M 0.0692474,6.76634C -2.5902,6.76634 -4.91351,8.20551 -6.16436,10.3475L 0.0665311,-10.3179L 6.29167,10.3284C 5.03818,8.19696 2.72079,6.76634 0.0692474,6.76634 Z " />
  </Grid>
</DataTemplate>

It's clear for me how to apply Datatemplate to controls, such as buttons, textboxs, listviews and so on. 我很清楚如何将Datatemplate应用于控件,例如按钮,文本框,列表视图等。

The TemplatePartAttribute does what you like. TemplatePartAttribute可以满足您的需求。 See this tutorial for info on how to write a Custom Control that supports Templating and see how you can mix your shape in there. 有关如何编写支持模板的自定义控件的信息, 请参见本教程 ,以及如何在其中混合形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM