实现 IDataTemplate 接口
If you need more control over your DataTemplate
you can do this by creating a class which implements the IDataTemplate
-interface. With this interface you can create your own DataTemplate
not only respecting the DataType
of your data, but also its properties or whatever you like.
To use this interface you must implement the following two members in your class:
public bool Match(object data) { ... }
you need to check in this method if the provided data matches yourIDataTemplate
or not. You need to return true if the data matches, otherwise false.public IControl Build(object param) { ... }
In this method you need to build and return the control which represents your data.
Samples
Basic Example
Below is a very basic sample implementation of the IDataTemplate
-interface:
You can now use the class MyDataTemplate
in your view like this:
Advanced Samples
最后更新于