silverlight DataGridTemplateColumn 模板列 排序

DataGridTemplateColumn模板列 本身可以是图片、按钮。

想要实现排序功能如下

 <sdk:DataGrid Name="datagrid1" AutoGenerateColumns="False" Height="180" HorizontalAlignment="Left" Margin="84,51,0,0"  VerticalAlignment="Top" Width="238" ItemsSource="{Binding  Path=PersonDataList}">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTemplateColumn  SortMemberPath="star1"  Header="star1" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="100"   CellTemplate="{StaticResource DataLevelTemplate}" />
                <sdk:DataGridTemplateColumn SortMemberPath="star2"  Header="star2" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="100" CellTemplate="{StaticResource DataLevelEditTemplate}" />
                <sdk:DataGridTextColumn Header="编号" Binding="{Binding star3}"/>
                <sdk:DataGridTextColumn Header="名字" Binding="{Binding star4}"/>
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>

<DataTemplate 定义如下

 <DataTemplate x:Key="DataLevelTemplate" >
            <local:DataLevel  HorizontalAlignment="Left" VerticalAlignment="Center"  ShowColor= "{Binding Path=star1, Mode= OneWay, Converter={StaticResource DataLevelColorConverter}}" Stars="{Binding Path=star1, Mode=OneWay, Converter={StaticResource DataLevelConverter}}" ></local:DataLevel>
        </DataTemplate>
        <DataTemplate x:Key="DataLevelEditTemplate">
            <TextBlock  HorizontalAlignment="Center" VerticalAlignment="Center"  Text="{Binding Path=star2,Mode=OneWay}"></TextBlock>
        </DataTemplate>

模板列添加 CanUserSort="True" SortMemberPath="Age"

即可实现图片排序


你可能感兴趣的:(datagrid,header,Path,silverlight,binding,DataTemplate)