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>
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?
I have an application which is check the incoming Mails on the Server and refresh a List with X-Values in it. Now I want to Plot the incoming Mail count in a Live Chart. I use http://lvcharts.net for this.
I have two classes a Mail Object with the Count and a TimeStamp in it and a List Class with all Mail Objects in it.
Here is my sample(pseudo) XAMl code:
<liveCharts:BarChart Name="MailChart" Grid.Row="1" Grid.Column="0">
<liveCharts:BarChart.Series>
<liveCharts:BarSeries Title="Mails" Values= "{Binding MailCountList.Count}"></liveCharts:BarSeries>
......
......
<liveCharts:BarChart.AxisY>
<liveCharts:Axis Title="Time" Labels="{Binding MailCountList.Timestamp}">
......
The Objects are in a normal List with automatically Refesh I use MVVM.
My Question is:
How can I bind a List to a XAML Value Series ?
I have used an ObservableCollection to view the Content and a normal list to fill sort etc. the Xaml Code Looks Like:
<ListView ItemsSource="{Binding TableList}" Grid.Row="0">
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="ID" DisplayMemberBinding="{Binding ID}"/>
<GridViewColumn Width="180" Header="Name" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Width="100" Header="Group" DisplayMemberBinding="{Binding Group}"/>
<GridViewColumn Width="85" Header="Version" DisplayMemberBinding="{Binding Version}"/>
</GridView>
</ListView.View>
</ListView>
The Source of the ListView is in the ItemSource and to Display Multiple Rows I use GridViewColumn with Binding to the Object Values from the List in "DisplayMemberBinding"
I'm trying to bind to properties on my GridView's DataContext and use a DataTemplateSelector to assign the correct template to the cell, but I can't seem to find the correct way to do this. Binding to DisplayMemberBinding overrides the template selector, but setting the CellTemplateSelector property binds to the DataContext rather than the properties I want to select templates for.
This answer seems to describe exactly what I'm looking for, but I'm having trouble finding information on how to implement what it describes: https://stackoverflow.com/a/12519433/1756960 .
This is what I tried using that isn't working (simplified for posting):
<ListView ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name"
DisplayMemberBinding="{Binding Name}"
CellTemplateSelector="{StaticResource ContentTypeTemplateSelector}" />
<GridViewColumn Header="Data"
DisplayMemberBinding="{Binding}"
CellTemplateSelector="{StaticResource ContentTypeTemplateSelector}" />
</GridView>
</ListView.View>
</ListView>
The first thing I would recommend doing is to differentiate your Content Template selectors in one of two ways. The First is to simply have more than one template selector class. the second is to have two instances, whose templates are assign different bindings.
<Resources>
<ns:TemplateSelector x:Key="NameTemplateSelector">
<ns:TemplateSelector.Template1>
<DataTemplate>
<!-- Something bound to Name -->
</DataTemplate>
</ns:TemplateSelector.Template1>
</ns:TemplateSelector>
<ns:TemplateSelector x:Key="DataTemplateSelector">
<ns:TemplateSelector.Template1>
<DataTemplate>
<!-- Something bound to Data -->
</DataTemplate>
</ns:TemplateSelector.Template1>
</ns:TemplateSelector>
The reference to Attached Properties (see MSDN) would have you make a property, attach it to the template selector, and then access that data from the TemplateSelector's code.
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