Hide list title
Using Thumb will solve the problem. As well as
<ListView x:Name="MyListView"IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=Items}", Mode=Default,
Source={StaticResource DataProvider}}"
Thumb.DragDelta="Thumb_DragDelta">
public Window1()
{
InitializeComponent();
MyListView.AddHandler(Thumb.DragDeltaEvent,
new DragDeltaEventHandler(Thumb_DragDelta),
true );
void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
Thumb senderAsThumb = e.OriginalSource as Thumb;
GridViewColumnHeader header = senderAsThumb.TemplatedParent as GridViewColumnHeader;
if (header.Column.ActualWidth < MIN_WIDTH)
{
header.Column.Width = MIN_WIDTH;
}
if (header.Column.ActualWidth > MAX_WIDTH)
{
header.Column.Width = MAX_WIDTH;
}
}
}
a source to share
Could you please provide some xaml for how your list looks like?
You can bind a RelayCommand to your button and pass the ListView as a parameter. Then you can set Visibility = False.
<Button Command="{Binding MyButtonCommand}
CommandParameter="{Binding ElementName=Col3}" />
This will be your cs:
ICommand _myButtonCommand;
public ICommand MyButtonCommand
{
get
{
if (_myButtonCommand== null) _myButtonCommand= new RelayCommand(param => HideList(param ));
return _myButtonCommand;
}
}
void HideList(object param){
(param as ListView).Visibility = False;
}
I am talking about RelayCommand like in Josh Smith's example: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
you can do the code there.
I think you could achieve a similar result in xaml with just triggers, however I am not that experienced with the subject.
a source to share
I am using code like
<Grid>
<ListView HorizontalContentAlignment="Stretch" Margin="38,12,31,110">
<ListView.View>
<GridView>
<GridViewColumn Header="COL1" Width="100"/>
<GridViewColumn Header="COL2" Width="100"/>
<GridViewColumn Header="COL3" Width="100"/>
</GridView>
</ListView.View>
</ListView>
<Button Height="25" HorizontalAlignment="Left" Margin="105,0,0,51"
Name="Collapse" VerticalAlignment="Bottom" Width="75"
Command="{Binding MyButtonCommand}"
CommandParameter="{Binding ElementName = COL3}">Collapse</Button>
<Button Height="25" HorizontalAlignment="Right" Margin="0,0,111,51" Name="Expand"
VerticalAlignment="Bottom" Width="75">Expand</Button>
</Grid>
and in CS
ICommand _myButtonCommand;
public ICommand MyButtonCommand
{
get
{
if (_myButtonCommand== null) _myButtonCommand = new RelayCommand(param => HideList(param ));
return _myButtonCommand;
}
}
void HideList( object param )
{
( param as ListView ).Visibility = Visibility.Hidden;
}
Can you give me a better idea?
a source to share
I would put this answer as a comment on your post, but I cannot comment yet, so ...
You must specify (use the "Name" property) the element you want to access through the "Binding ElementName", or you will not be able to get it. In your case, you must explicitly create a GridViewColumnHeader because the GridViewColumn does not have a Visibilty property:
<GridViewColumnHeader Name="COL3">COL3</GridViewColumnHeader>
You probably also need to explicitly create the content of your GridViewColumn if you want it to disappear. This means that you need to use the GridViewColumn.DisplayMemberBinding or GridViewColumn.CellTemplate and give them a name or access them through the RelativeSource.
Look at this for possibilities: http://www.wpfwiki.com/Default.aspx?Page=WPF%20Q5.3&AspxAutoDetectCookieSupport=1
However, have you considered using an extender?
a source to share