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. rtems 4.11 时钟驱动(arm, beagle)

    根据bsp_howto手册,时钟驱动的框架主要在 c/src/lib/libbsp/shared/Clockdrv_shell.h 文件中实现 时钟初始化 时钟驱动初始化函数为 Clock_initi ...

  2. Proving Equivalences (hdu 2767 强联通缩点)

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. Unity3D研究院编辑器之脚本设置ToolBar及脚本设置顶视图

    Unity版本5.3.2 如下图所示,ToolBar就是Unity顶部的那一横条.这里的所有按钮一般情况下都得我们手动的用鼠标去点击.这篇文章我们说说如果自动操作它们 1.自动点击左边四个按钮 (拖动 ...

  4. Android中List循环遍历性能对照

    在android开发中仅仅要是列表式风格界面我们差点儿都须要用到List来存放数据,在数量非常少的List的话差点儿不论什么一种循环遍历方式总体性能都无区别.可是当我们遇到数据量稍大的时候有必要考虑用 ...

  5. Times[2017-01-25at JiNan]

    Times[问题描述 ]小 y 作为一名资深的 dotaer,对视野的控制有着深刻的研究.每个单位在一段特定的时间内会出现在小 y 的视野内,除此之外的时间都在小 y 看不到的地方.在小 y 看来,视 ...

  6. dom 显示 与否 的对 ecmascript 变量的 监听

    dom 显示 与否  的对 ecmascript   变量的 监听

  7. mysql随机查询

    select * from table as t1 join (select round(rand() * ((select max(id) from table)-(select min(id) f ...

  8. 远程服务器上的weblogic项目管理(三)常用指令及常见错误

    weblogic的管理流程已在前两节整理完毕,接下来汇总一下linux环境下的weblogic管理常用指令及常见错误: 常用指令: ./startWebLogic.sh 启动weblogic ./st ...

  9. 【题解】kth异或和/魔改版线性基

    [题解]魔改版线性基 魔改版线性基解决此类问题. 联系线性空间的性质,我们直接可以构造出这样的基: \[ 100000 \\ 010000 \\ 000010 \\ 000001 \] 使得每个基的最 ...

  10. 【题解】quake

    [题解]\(quake\) 题目大意 我们共有报酬\(f\)元,一条边有它的价值\(w_i\),有它的建造时间\(t_i\).要求建一些边,生成一颗树.求最大的利润率. 数据范围 \(n\le 400 ...