• WPF GridView中的CellTemplate失效的原因


    最近做一个ListView的Style时,发现一个问题, 就是我的GridView的GridViewColumn的CellTemplate无论是用StaticResource还是DynamicResource,都是没有效果。

    原因:GridViewColumn用了DisplayMemberBinding 使得CellTemplate失效。 

    解决办法: 去掉DisplayMemberBinding, 在CellTemplate的模板中指定Path路径。 比如:

                                    <DataTemplate x:Key="GridViewHeaderTemplate1">
                                                                    <StackPanel>
                                                                                    <TextBlock  Text="{Binding Mode=OneWay}"/>
                                                                                    <TextBox  TextWrapping="Wrap" Text="" MinWidth="25"/>
                                                                    </StackPanel>
                                                    </DataTemplate>
                                                    
                                                    <DataTemplate x:Key="StatusDataTemplate">
                                                                    <CheckBox IsChecked="{Binding Status}"></CheckBox>
                                                    </DataTemplate>

    <GridViewColumn HeaderTemplate="{StaticResource GridViewHeaderTemplate1}" CellTemplate="{StaticResource StatusDataTemplate}"  Header="Status" />

    如果你不想用CellTemplate指定Binding的path, 可以通过<GridViewColumn HeaderTemplate="{StaticResource GridViewHeaderTemplate1}" DisplayMemberBinding="{Binding Status}"  Header="Status" />
  • 相关阅读:
    逆序数 POJ 2299 Ultra-QuickSort
    DP URAL 1244 Gentlemen
    找规律 SGU 107 987654321 problem
    找规律 SGU 126 Boxes
    DP VK Cup 2012 Qualification Round D. Palindrome pairs
    模拟 Coder-Strike 2014
    模拟 Codeforces Round #203 (Div. 2) C. Bombs
    DFS HDOJ 2614 Beat
    最短路(Floyd_Warshall) POJ 2240 Arbitrage
    最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3169070.html
Copyright © 2020-2023  润新知