What controls are used to create an Excel-like grid with columns with headers and the columns can be resized?
In regular WPF, it was this:
<ListView>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name1}" Header="Name1"
Width="Auto" />
</GridView>
</ListView.View>
</ListView>
This displays Excel-like grid with one column with header and the whole column can be resized. But in Universal Windows Apps/WinRT, there is no GridViewColumn. How do I go about duplicating this code in Universal Windows Apps?
Related
I have a ListView which looks like this:
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<ListView>
<ListView.View>
<GridView>
<GridView.Columns>
...
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
There are +-30 columns, so it's a very wide screen. When the user scrolls to the right, I still want him to know which column he's on. The first four columns contain that information (ID, name, ...), so I want to freeze these columns.
Also, I'm using GridViewSort so using two ListViews will cause the sort to not work anymore.
How can I achieve this?
What I want is to have a table having a first column with every row named by me one by one, not binding to some property. But all of the second column should be binded to a property. I cannot do these two with gridview since it only makes binding and does not let me to write something manually. On the other hand, I havent seen any flowdocument table tutorial in which someone mention binding. So what is the proper object suitable to fulfill mentioned two things?
ListView and GridView should meet your requirements. You have the ability to set bindings on the GridViewColumns by using DisplayMemberPath or in the CellTemplate. You can also choose not to use bindings in a column.
Take this for example:
<ListView ItemsSource="{Binding NameValuePairs}">
<ListView.Resources>
<DataTemplate x:Key="FirstCellTemplate">
<Grid Width="100">
<TextBox Width="75"/>
</Grid>
</DataTemplate>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource FirstCellTemplate}"/>
<GridViewColumn DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn DisplayMemberBinding="{Binding Value}"/>
</GridView>
</ListView.View>
</ListView>
NameValuePairs is an ObservableCollection<NameValuePair> and NameValuePair is a view model with a Name and Value properties. The first column is contains a TextBox on each row, the second is a TextBlock with the Name, and the third is a TextBlock with the Value.
I've looked at a bunch of different controls(ListView, GridView, etc.) and can't decide which makes the most sense for me to use.
I want something that looks and functions just like a listBox with the ability to select a row with a single click, except it would contain data with multiple columns.
I'm just looking for suggestions on which control to use and how I would go about having it select a row(whether it's a selectionMode or an onClick function or what). Since I'm new to these controls I'd like some direction on which tag to place those selection options, I think I can figure out the rest however.
Thanks :)
I like using the ListView that contains a GridView as it's view. Here's how I defined it in XAML:
<ListView Name="lstCurrentInvoices" Grid.Row="4" Margin="0,0,0,0" SelectionMode="Extended" ToolTip="Invoices included in invoice file." IsTabStop="True" TabIndex="8">
<ListView.View>
<GridView>
<GridViewColumn Width="40" Header="ID" DisplayMemberBinding="{Binding ClientId}"/>
<GridViewColumn Width="170" Header="Name" DisplayMemberBinding="{Binding ClientName}"/>
<GridViewColumn Width="80" Header="Date" DisplayMemberBinding="{Binding InvoiceDate}"/>
<GridViewColumn Width="40" Header="Frequency" DisplayMemberBinding="{Binding Frequency}" />
</GridView>
</ListView.View>
</ListView>
This way you kind of get the best of both worlds. In this example, you can have multiple rows selected. You can detect which rows have been selected and grab the objects from you data source. It's really quite powerful. Hope this helps
I'm trying to create a Table inside a FlowDocument inside a FlowDocumentPageViewer, as seen in this tutorial. I've never created a table in WPF before, and I was expecting there to be an ItemsSourceproperty to which I could bind, like with a ListBox. I want to customize the template for each row, and I want each row's source to be an item in a collection that I pass to the entire table. So I'll have a List<MyClass> instance that would be passed to the table, and each row would show a single MyClass. How can I do that? Do I not want to use a Table within a FlowDocument? The reason I wanted to use some kind of tabular format is so that I can have a single row of column names that applies to all the rows.
I think what I wanted was to use ListView, thanks to this tutorial:
<ListView Grid.Row="0" ItemsSource="{Binding Path=MyList}" MinWidth="400"
MinHeight="200">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn
DisplayMemberBinding="{Binding Path=MyFirstField}"
Header="First Field"/>
<GridViewColumn
DisplayMemberBinding="{Binding Path=MySecondField}"
Header="Second Field"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
How can I make a ListView imitate the ListView in Windows Explorer on the right side. Like how can I get icons in the ListView and get the arrows?
You can find the icons by using Google Image search. To create the ListView, you could do something like this is XAML:
<Grid>
<ListView ItemsSource="{Binding ListViewSource}">
<ListView.View>
<GridView>
<GridViewColumn Width="25">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Icon}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding FileName}" Width="250"/>
<GridViewColumn Header="Date Modified" DisplayMemberBinding="{Binding DateModified}" Width="100"/>
<GridViewColumn Header="Type" DisplayMemberBinding="{Binding FileType}" Width="100"/>
<GridViewColumn Header="Size" DisplayMemberBinding="{Binding FileSize}" Width="100"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
The next step is to create an ObservableCollection to hold all of the items in your list and call it ListViewSource. You can populate this collection with actual FileDirectory information, or your own kind of list. You'll then want to create your logic as to what happens when you doubleclick on an item. Since your question didn't specify to what detail you want the ListView to work, I'm going to stop there. Let us know if you want it to behave just like Windows Explorer, and we'll try to help you out.