如何将此模板放入资源中:
<telerikGridView:RadGridView x:Name="MyGridView" ItemsSource="{Binding MySource}" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerikGridView:GridViewColumn Header="Id">
<telerikGridView:GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ID}" />
</DataTemplate>
</telerikGridView:GridViewColumn.CellTemplate>
</telerikGridView:GridViewColumn>
<telerikGridView:GridViewColumn Header="Name">
<telerikGridView:GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NAME}" />
</DataTemplate>
</telerikGridView:GridViewColumn.CellTemplate>
</telerikGridView:GridViewColumn>
</telerik:RadGridView.Columns>
</telerikGridView:RadGridView>
我还有2个具有相同模板的网格。
答案 0 :(得分:1)
创建字典文件并在App.xaml中添加其引用
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resourses/DataTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
资源文件内容......
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
mc:Ignorable="d">
<DataTemplate x:Key="GridIDTemplate">
<TextBlock Text="{Binding ID}" />
</DataTemplate>
<DataTemplate x:Key="GridNameTemplate">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ResourceDictionary>
并在您的文件中按名称引用数据模板
<telerikGridView:RadGridView x:Name="MyGridView" ItemsSource="{Binding MySource}" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerikGridView:GridViewColumn Header="Id" CellTemplate="{StaticResource GridIDTemplate}" />
<telerikGridView:GridViewColumn Header="Name" CellTemplate="{StaticResource GridNameTemplate}">
</telerik:RadGridView.Columns>
</telerikGridView:RadGridView>