Datagrid有多个bug;
1,不支持DynamicResource的东西
2, 在Column隐藏后再显示, ColumnHeader的Tag或者DataContext为null。
解决办法:
用StaticResource ,如下面的 StaticResource DGC_ContentTemplate;
用DataGridColumnHeader的Column,来取得上层的datacontext。如, ItemsSource="{Binding Path=Column.Tag, Converter ={StaticResource DebugConverter}, Mode=OneWay, RelativeSource={RelativeSource   FindAncestor, AncestorType={x: Type DataGridColumnHeader}}}"
   private void InitDataGridBinding (DataGridColumnEx col, string path)
        {
            if (null == col || String.IsNullOrWhiteSpace (path) || null == col .Header)
            {
                return;
            }
            Binding binding = new Binding();
            binding.Mode = BindingMode. OneWay;
            binding.RelativeSource = new RelativeSource(RelativeSourceMode .Self);
            binding.Converter = new BoolToVisibilityConverter();
            binding.Path = new PropertyPath("(FrameworkElement.DataContext).PACfgVM." + path + ".CfgInfo[" + PAAttachedProperty. GetName(col ) + "].IsVisiable");
            BindingOperations.SetBinding (col, DataGridColumnEx.VisibilityProperty , binding);
            //{for combobox binding in columnHeader
            col.Tag = PAAttachedProperty. GetTag(col );
            DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor .FromProperty( DataGridColumnEx.VisibilityProperty , typeof(DataGridColumnEx ));
            if (dpd != null)
            {
                dpd.AddValueChanged (col, delegate
                {
                    //
                    InitDataGridColumnHeader(col , GetDataGridParent( col));
                });
            }
            //}
        }
             <DataTemplate x :Key="DGC_ContentTemplate">
                <TextBlock TextWrapping ="Wrap" Text="{ Binding }" MinWidth ="20"/>
            </DataTemplate>
  <Style x:Key ="DataGridColumnHeaderStyle_ComboBox" TargetType="{x :Type DataGridColumnHeader}">
                <Setter Property ="ContentTemplate" Value="{ StaticResource DGC_ContentTemplate}"/>
                <Setter Property ="VerticalContentAlignment" Value="Center"/>
                                 <Setter Property ="Template">
                                                 <Setter.Value>
                                                                 <ControlTemplate TargetType ="{x: Type DataGridColumnHeader}">
                            <Grid>
                                                                                                 <StackPanel Orientation ="Vertical" d:LayoutOverrides="Height" Margin="10">
                                    <Label Foreground ="Black" HorizontalContentAlignment="Left" Content="{TemplateBinding Content }"/>
                                    <!--<ComboBox Margin="0,10,0,0" ItemsSource="{Binding (FrameworkElement.Column.).TimeSearchGroup, Converter={StaticResource DebugConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"/>-->
                                    <!--<ComboBox Margin="0,10,0,0"
                                              ItemsSource="{Binding Path=Tag, Converter={StaticResource DebugConverter}, Mode=OneWay, RelativeSource={RelativeSource  FindAncestor, AncestorType={x:Type DataGridColumnHeader}}}"></ComboBox>-->
                                    <ComboBox Margin ="0,10,0,0"
                                              ItemsSource="{Binding Path=Column.Tag, Converter ={StaticResource DebugConverter}, Mode=OneWay, RelativeSource={RelativeSource   FindAncestor, AncestorType={x: Type DataGridColumnHeader}}}"></ ComboBox>
                                </StackPanel>                                                                                                        
                                                                                                 <Thumb x :Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Style="{StaticResource ColumnHeaderGripperStyle}"/>
                                                                                                 <Thumb x :Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Style="{StaticResource ColumnHeaderGripperStyle}"/>
                                                                                 </Grid>
                                                                 </ControlTemplate>
                                                 </Setter.Value>
                                 </Setter>
                <EventSetter Event ="Selector.SelectionChanged" Handler="ComboBox_SelectionChanged"/>
            </Style>

DataGridColum的bug的更多相关文章

  1. Tomcat一个BUG造成CLOSE_WAIT

    之前应该提过,我们线上架构整体重新架设了,应用层面使用的是Spring Boot,前段日子因为一些第三方的原因,略有些匆忙的提前开始线上的内测了.然后运维发现了个问题,服务器的HTTPS端口有大量的C ...

  2. a标签点击跳转失效--IE6、7的奇葩bug

    一般运用a标签包含img去实现点击图片跳转的功能,这是前端经常要用到的东西. 今天遇到个神奇的bug:如果在img上再包裹一层div,而且div设置了width和height,则图片区域点击时,无任何 ...

  3. 关于 Chrome 浏览器中 onresize 事件的 Bug

    我在写插件时用到了 onresize 事件,在反复地测试后发现该事件在 Chrome 及 Opera(内核基本与 Chrome 相同,以下统称 Chrome)浏览器打开时就会执行,这种情况也许不能算作 ...

  4. Chrome出了个小bug:论如何在Chrome下劫持原生只读对象

    Chrome出了个小bug:论如何在Chrome下劫持原生只读对象 概述 众所周知,虽然JavaScript是个很灵活的语言,浏览器里很多原生的方法都可以随意覆盖或者重写,比如alert.但是为了保证 ...

  5. 一个粗心的Bug,JSON格式不规范导致AJAX错误

    一.事件回放  今天工作时碰到了一个奇怪的问题,这个问题很早很早以前也碰到过,不过没想到过这么久了竟然又栽在这里. 当时正在联调一个项目,由于后端没有提供数据接口,于是我直接本地建立了一个 json ...

  6. 了不起的 nodejs-TwitterWeb 案例 bug 解决

    了不起的nodejs算是一本不错的入门书,不过书中个别案例存在bug,按照书中源码无法做出和书中相同效果,原本兴奋的心情掺杂着些许失落. 现在我们看一下第七章HTTP,一个Twitter Web客户端 ...

  7. 应该是Angular2的一个bug?

    为了应对未来的趋势,及时赶上下一趟互联网技术,我最近也在通过具体项目研究angular2,首先必须要吐槽的是,学习angular2的成本本身不高,但是一堆的工具.配置实在让人 很是焦灼,就像asp.n ...

  8. 记录一次bug解决过程:数据迁移

    一 总结 不擅长语言表达,勤于沟通,多锻炼 调试MyBatis中SQL语法:foreach 问题:缺少关键字VALUES.很遗憾:它的错误报的让人找不着北. 二 BUG描述:MyBatis中批量插入数 ...

  9. 关于MJRefresh的下拉加载数据bug

    当没有更多数据的时候显示NoMoreData 我的理解是先结束刷新再显示没有更多 今天之前一直没发现有问题 贴之前的代码 [self.collectionView reloadData]; [self ...

随机推荐

  1. GIT简单使用——多人协作篇

    多人协作的工作模式通常是这样:1.首先,可以试图用git push origin <branch-name>推送自己的修改:2.如果推送失败,则因为远程分支比你的本地更新,需要先用git ...

  2. c# .net Global.asax文件的作用

    1 Global.asax文件的作用 先看看MSDN的解释,Global.asax 文件(也称为 ASP.NET 应用程序文件)是一个可选的文件,该文件包含响应 ASP.NET 或HTTP模块所引发的 ...

  3. os引导程序boot从扇区拷贝os加载程序loader文件到内存(boot copy kernel to mem in the same method)

    [0]README 0.1) 本代码旨在演示 在boot 代码中,如何 通过 loader文件所在根目录条目 找出该文件的 在 软盘所有全局扇区号(簇号),并执行内存中的 loader 代码: 0.2 ...

  4. java 面试总结

    1.static变量与实体变量的差别? static是静态变量,static能够通过类名直接訪问 内存方面的不同:static在定义的时候jvm就会分配空间, 而实体变量仅仅有在创建对象的时候才会去分 ...

  5. struts2 jsp提交日期类型转换及国际化实现

    概述:下面通过jsp提交输入注册信息信息,同时完成过程文件国家化问题演示说明.[注册日期转换用注解方式实现] 工程截图: 注册页面jsp文件: <%@ page language="j ...

  6. sql 时间转换格式

    convert(varchar(10),字段名,转换格式) CONVERT(nvarchar(10),count_time,121)CONVERT为日期转换函数,一般就是在时间类型(datetime, ...

  7. UIScrollView奇葩不滑动

    首先要说声尼玛,真奇葩,从来都没有遇到过这个问题,首先描述一下背景: 我是用XIB拖拽了一个UIScrollView在View上,然后设置了frame,在ViewDidLoad里面,设置了scroll ...

  8. 在ios中使用单例模式编程

    本文转载至 http://blog.csdn.net/remote_roamer/article/details/7107007     1.    @implementation Singleton ...

  9. vue element-ui 自动获取光标

    <el-input ref="customerInput"></el-input> this.$refs.mark.$el.querySelector('i ...

  10. JSON格式之GSON解析

    JSON格式之GSON解析 最近在做websocket相关,项目需要JSON解析.相较之下感觉google的GSON解析不错. JAVA后台 Gson提供了fromJson()方法来实现从Json相关 ...