Binding Visible property of a DataGridColumn in WPF DataGrid

前端 未结 4 1192
情歌与酒
情歌与酒 2020-12-10 21:23

I cannot bind the Visible property of the WPF datagridtextcolumn to a boolean value.

My binding expression is,

{Binding Path=DataContext.IsThisColumn         


        
相关标签:
4条回答
  • 2020-12-10 21:31

    Hard to say from so little of your code. What is in Visual Studio's Output window (under Debug)? That will often give you a clue as to the problem.

    0 讨论(0)
  • 2020-12-10 21:40

    I worked this out.

    DataGridCOlumn is not a framework element so the FindAncestor call was failing (DataGridColumn not part of visual tree)

    Have to set source property of binding expression to a staticresource and it works fine.

    0 讨论(0)
  • 2020-12-10 21:42

    If you can bind from code you can use

    BindingOperations.SetBinding(DatagridColumInstance,
                                 DatagridColum.VisibilityProperty,
                                 myNewBindDef);
    
    0 讨论(0)
  • 2020-12-10 21:45

    I was looking for the same thing and found an execellent way to do it in an article about forwarding datacontext to columns.

    0 讨论(0)
提交回复
热议问题