So far my experience with WPF has been well met, it is an extremely flexible system with a nearly limitless possibilities with customizing controls. However, with flexibility often comes complexity. So I have been messing with the ListView control and was trying to figure out how to hide the column headers, is it possible? It didn't seem like the control even supported it...But then I remembered reading about Styles and how you can set nearly any property with a style, on any control whether its nested deep in the controls hierarchy or not.
So that's exactly what I did, and you can see my XAML for that below:
1: <GridView>
2: <GridView.ColumnHeaderContainerStyle>
3: <Style TargetType="GridViewColumnHeader">
4: <Setter Property="Visibility" Value="Hidden" />
5: <Setter Property="Height" Value="0" />
6: </Style>
7: </GridView.ColumnHeaderContainerStyle>
If there is an easier way to do that then I am all ears, please share the knowledge!
The next step in my customizing quest was I wanted two columns, the first one to show an icon, the second one to show text. However, the ListView control was inside of a grid column with a grid splitter so this column could get bigger and the control along with it. Which was desired, if you make the control bigger I wanted the text that was Ellipsed due to not enough space to show.
This presented a problem, first how do you get the second column to take up the remaining room of the control? Secondly, how do you get the text to ellipse when the control is cutting the text off?
The first one was not so easy to solve, and I actually never came up with a solid solution, more of a hack really and it only works since in my instance I don't need to have horizontal scrolling ability inside my ListView control. So the solution was to hide the horizontal scrollbar and set the column width to a very high number, which works but it's really a dirty solution. Until someone can offer me a better solution this is the only one I could come up with.
Note: I solved this problem without the hack in a later post, you can view it here.
Ellipse Text XAML:
1: <GridViewColumn.CellTemplate>
2: <DataTemplate>
3: <Label HorizontalAlignment="Stretch">
4: <TextBlock Text="{Binding Path=Name}" Width="Auto" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis" /> 5: <Label.ToolTip>
6: <ToolTip>
7: <TextBlock Text="{Binding Path=Name}" /> 8: </ToolTip>
9: </Label.ToolTip>
10: </Label>
11: </DataTemplate>
12: </GridViewColumn.CellTemplate>
Hide Horizontal Scrollbar XAML:
<ListView ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
Last but least, normally each ListViewItem is only large enough to fit the contents. In order to avoid this we set the ListView.ItemContainerStyle as seen below:
1: <ListView.ItemContainerStyle>
2: <Style TargetType="{x:Type ListViewItem}"><Setter Property="HorizontalContentAlignment" Value="Stretch" /> 3: </Style>
4: </ListView.ItemContainerStyle>
So that's basically it for now, if you have any cool stuff you have find be sure to send them my way. I am gathering that WPF is going to be a huge learning curve for everyone, going to take quit a while to get elite at this stuff. Designers will be able to have a field day, but more often than not us poor developers are left doing both design and development.