0
    <ListView Grid.Row="1" Margin="10" Name="lvRegistersConfig" ItemsSource="{Binding registers}">
        <ListView.Resources>
            <local:BoolToVisibility x:Key="BTVConverter"/>
        </ListView.Resources>
        <ListView.View>
            <GridView>
                <local:GridViewColumnExt Header="Register Name" Width="100" Visibility="{Binding Vis, Converter={StaticResource BTVConverter}}" >
                    <local:GridViewColumnExt.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" Visibility="{Binding Vis, Converter={StaticResource BTVConverter}}"/>
                        </DataTemplate>
                    </local:GridViewColumnExt.CellTemplate>
                </local:GridViewColumnExt>
            </GridView>
        </ListView.View>
    </ListView>

GridViewColumnExt is a class that inherits from GridViewColumn and adds the Visibility property.

My ListView's ItemsSource as you may see, is set to be the registers ObservableCollection. Register class has a property of type bool named Vis. It all works fine for the TextBox, but from the GridViewColumnExt don't, i think i cannot reach the collection and bind to the specific object.

I am not sure what's the DataContext for the GridViewColumn, i saw that i cannot set it. I need a hint on this, how can my GridViewColumn see the Vis property from the Register object in the registers ObservableCollection ?

Olaru Mircea
  • 2,570
  • 26
  • 49
  • Adding a Visibility binding for an entire column based on a property of an individual item doesn't make any sense. What if item 1 has Vis = true and item 2 has Vis = false, do you hide the entire column or not? – user3910810 Aug 09 '14 at 19:27
  • @user3910810 if any item exists on that column i will display it. I have my ListView inside an expander and i am checking that on the expanded event. – Olaru Mircea Aug 09 '14 at 19:32
  • http://stackoverflow.com/questions/6857780/how-to-hide-wpf-datagrid-columns-depending-on-a-property – yo chauhan Aug 09 '14 at 22:00

1 Answers1

0

I'm not sure how the GridViewColumnExt control works, but it looks like with your XAML that the DataContext is not going to be individual item in the registers collection, rather it is the same DataContext on which the registers collection is declared. So, you're probably not going to be able to control the visibility of the column with the Register.Vis property.

If you're looking to put more in your cell template, you could wrap the TextBlock in a Grid and bind the Grid.Visibility property to the Register.Vis property.

Does that make sense?

Michael Nero
  • 1,396
  • 13
  • 24