How to create Check box for Column inside Listview. i was able to make checkbox for listview items. but i want to have checkbox for Column itself.like in windows:
here is code in XAML
<ListView HorizontalAlignment="Left" Grid.Row="1" Width="400">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Column1 With Checkbox">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding}" IsThreeState="False" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="140" Header="Column2" />
<GridViewColumn Width="115" Header="Column3" />
</GridView>
</ListView.View>
</ListView>
Note that this will only make checkboxes for items not Column itself. so how to make this happen?
You can make the header a custom control by defining it under the GridViewColumn.Header property.
<ListView HorizontalAlignment="Left" Grid.Row="1" Width="400">
<ListView.View>
<GridView>
<GridViewColumn Width="140">
<GridViewColumn.Header>
<StackPanel Orientation="Horizontal">
<Checkbox IsChecked="{Binding YourCheckedProperty}" />
<TextBlock Text="Column1" />
</StackPanel>
<GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn Width="140" Header="Column2" />
<GridViewColumn Width="115" Header="Column3" />
</GridView>
</ListView.View>
</ListView>
Related
How do I wrap text in a Grid?
In MainWindow.xaml
<Grid>
<ListView Margin="10" Name="Users" >
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="300" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Age" Width="200" DisplayMemberBinding="{Binding Age}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
In MainWindow.xaml.cs
public ObservableCollection<User> items = new ObservableCollection<User>();
items.Add(new User() { Name = "John", Age = 42 });
Users.ItemsSource = items;
You should create DataTemplate for the GridViewColumn and place TextBlock. Then it is possible to use TextWrapping property. Work example:
<ListView Name="Users">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="385">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Age" Width="385">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding Age}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
How do I insert a horizontal line after each list view item in a grid?
<Grid>
<ListView Margin="10" Name="Users">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="300">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" TextTrimming="WordEllipsis" Height="32" Text="{Binding Name}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Age" Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" TextTrimming="WordEllipsis" Height="32" Text="{Binding Age}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
I tried defining Border after DataTemplate
<DataTemplate>
<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue">
but that only added a border around each of the data template items. How do I insert a horizontal separator after each row?
I think you ought to be able to set a row style via the ItemContainerStyle:
https://stackoverflow.com/a/4474474/424129
You'd want to set a BorderThickness="0,0,0,1" to have only a bottom border.
There probably was a topic in which lays the solution for my problem but I've spend too much hours on this so I've decided to ask.
I have a ListView to which I've binded a collection of processes. And I have a ListBox in which I want to place Threads of a selected process. Binding in ListView works, but analogical in ListBox doesn't.
Here's my .xaml:
<Window x:Class="TaskManager.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window" Height="453" Width="533" Icon="/TaskManager;component/Images/taskmgr.png">
<Grid>
<ListView Height="276" HorizontalAlignment="Left" Name="processesView" VerticalAlignment="Top" Width="503" ItemsSource="{Binding ProcessList}">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn DisplayMemberBinding="{Binding ProcessName}">
<GridViewColumn.Header>
<GridViewColumnHeader Click="nameColumnHeader_Click">
Name
</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Id}">
<GridViewColumn.Header>
<GridViewColumnHeader Click="IDColumnHeader_Click">
ID
</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding BasePriority}">
<GridViewColumn.Header>
<GridViewColumnHeader Click="priorityColumnHeader_Click">
Priority
</GridViewColumnHeader>
</GridViewColumn.Header>
</GridViewColumn>
<GridViewColumn Header="Keep alive">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="keepAliveBox" IsChecked="{Binding EnableRaisingEvents}" Checked="keepAliveBox_Checked" Unchecked="keepAliveBox_Unchecked" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListBox Height="120" HorizontalAlignment="Left" Margin="93,282,0,0" Name="threadBox" VerticalAlignment="Top" Width="200" ItemsSource="{Binding ElementName=processesView, Path=SelectedItem.Threads}">
<ListBox.ItemTemplate>
<DataTemplate>
<!--<ListBoxItem Content="{Binding}"/>-->
<Label Content="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
After execution I can't see anything in the ListBox but if I click inside something is selected. So if I change the above to Content="TEST" I can see several Labels with "TEST" value. So it seems that I'm binding the name somehow incorrectly.
Here's the .cs part where I set the context:
public MainWindow()
{
InitializeComponent();
processesView.DataContext = this;
threadBox.DataContext = this;
...
}
Items were invisible but selectable so it was probable that I was binding the wrong thing. And that's the reason. I was binding to Name property of Thread whilst Process has a collection of ProcessThreads which don't have that property. Here's the fix in .xaml:
<ListBox Height="120" HorizontalAlignment="Left" Margin="93,282,0,0" Name="threadBox" VerticalAlignment="Top" Width="200" ItemsSource="{Binding ElementName=processesView, Path=SelectedItem.Threads}">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Path=Id}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Can't wait for XAML debugger in Visual Studio 2015.
I have a WPF project developed with VS 2008 that is using version 3.5 of the .NET framework. The initial window width is set to 680 and SizeToContent is set to "Width" only. There are 3 ListView controls that are placed in a grid panel in this window. The first 2 grids both have one column where the width is specified. The 3rd ListView control does not specify the width of any column. When the ListView controls are initially filled with data, the window is properly resized. If additional data comes in to the 3rd ListView, then the window shrinks or grows the width appropriately. However, if the 1st or 2nd ListView container grows or shrinks - especially if the scrollbars are removed by increasing the window size vertically, then the width of the window is not correctly updated. Does anyone have any ideas as to how I can get the window to resize properly when the 2nd and 3rd ListView controls are updated?
Here is my XAML code for the window and ListView controls:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AP2"
x:Class="AP2.MainWindow"
x:Name="LobbyWindow"
Title="Lobby"
Height="480"
mc:Ignorable="d"
SizeToContent="Width"
MinWidth="680"
MinHeight="480"
SizeChanged="LobbyWindow_SizeChanged"
Loaded="LobbyWindow_Loaded"
Closing="LobbyWindow_Closing"
StateChanged="LobbyWindow_StateChanged">
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FF434D7A"
Offset="0" />
<GradientStop Color="#FF180CFA"
Offset="1" />
</LinearGradientBrush>
</Window.Background>
...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.064*" />
<RowDefinition Height="0.936*" />
</Grid.RowDefinitions>
<!-- Define the selected table label. -->
<Label x:Name="SelTableLabel"
Margin="1,-5,0,0"
Content="Table"
FontSize="11"
Foreground="#FF000000"
Background="#FFFFFFFF"
Grid.Row="0"
Grid.Column="2"
FontFamily="Georgia"
FontWeight="Bold"
VerticalAlignment="Bottom" />
<ListView x:Name="ListView1"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
SelectionChanged="ListView1_SelectionChanged"
Grid.Row="1"
Grid.Column="0"
SelectionMode="Multiple"
ItemsSource="{Binding ElementName=LobbyWindow, Path=ListCollection1}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Game}">
<GridViewColumnHeader Content="Game"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Stakes}">
<GridViewColumnHeader Content="Stakes"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn Width="30"
DisplayMemberBinding="{Binding Seats}">
<GridViewColumnHeader Content="Seats"
FontWeight="Bold" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="ListView2"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
Grid.Row="1"
Grid.Column="1"
SelectionChanged="ListView2_SelectionChanged"
SelectionMode="Single"
ItemsSource="{Binding ElementName=LobbyWindow, Path=ListCollection2}">
<ListView.View>
<GridView>
<GridViewColumn Width="90"
x:Name="TableName"
DisplayMemberBinding="{Binding TableName}">
<GridViewColumnHeader Content="Table"
Width="90"
FontWeight="Bold"
HorizontalAlignment="Left" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Stakes}">
<GridViewColumnHeader Content="Stakes"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding NumPlayers}">
<GridViewColumnHeader Content="Players"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Speed}">
<GridViewColumnHeader Content="Speed"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding HandsPerHour}">
<GridViewColumnHeader Content="H/Hr"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding AvgPotSize}">
<GridViewColumnHeader Content="Avg Pot"
FontWeight="Bold" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="ListView3"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
Grid.Row="1"
Grid.Column="2"
SelectionMode="Single"
ItemsSource="{Binding ElementName=LobbyWindow, Path=ListCollection3}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Player}">
<GridViewColumnHeader Content="Player"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding City}">
<GridViewColumnHeader Content="City"
FontWeight="Bold" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Chips}">
<GridViewColumnHeader Content="Chips"
FontWeight="Bold" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
I am trying to display groups(#'s) and the students who are in that group. I have two listview boxes on a page(wpf). The first listview box displays the group #. And the second listview box displays the first and lastnames of the group that i have selected in the 1st listview. I'm using observableCollection and binding through xaml. Can anybody tell me how I can display the students in the 2nd listview box depending on the group# i have selected in the first listview?
For example:
Listview(group#) box1: contains group numbers 1-20
Listview(names) box2: contains group firstname and lastname
So if i select group number 1(item1) in listview box1, then in listview box2, it should display the first and lastnames that are in that group#
Any help or advice is greatly appreciated. :)
<ListView HorizontalAlignment="Stretch" Margin="0,12" x:Name ="listViewGroups" ItemsSource="{Binding Groups}" DisplayMemberPath="bindMe" IsSynchronizedWithCurrentItem="{x:Null}" Grid.Column="1">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding GroupNumber}" Width="40">
<GridViewColumnHeader Tag="GroupNumber" Content="#" Click="SortClick" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding GroupLeader}" Width="120">
<GridViewColumnHeader Tag="GroupLeader" Content="Group Leader" Click="SortClick" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding GroupSize}" Width="70">
<GridViewColumnHeader Tag="GroupSize" Content="Group Size" Click="SortClick" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Label Content="Leader" Height="28" Margin="12,12,0,0" Name="lblFirstName" Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Left" />
<TextBox Text="{Binding SelectedItem.GroupLeader, ElementName =listViewGroups}" Height="23" Margin="12,31,0,0" Name="txtFirstName" MaxWidth="160" Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Left" Width="160" />
<Label Content="Group Members" Height="28" HorizontalAlignment="Left" Margin="14,60,0,0" Name="label1" VerticalAlignment="Top" Grid.Column="2" />
<ListView HorizontalAlignment="Stretch" Margin="12,80,188,12" x:Name ="listViewGroupMembers" ItemsSource="{Binding Groups}" IsSynchronizedWithCurrentItem="{x:Null}" VerticalAlignment="Stretch" Grid.Column="2">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding path SelectedItem.FirstName, ElementName= listViewGroups}" Width="100">
<GridViewColumnHeader Tag="Name" Content="First Name" Click="SortClick" />
</GridViewColumn>
</Listview>
I am Asumming that you have a Object Group and an Object Student
So your first ListView has ObservableCollection<Groups> and Each Group has a List of Students ObservableColection<Student> so in Xaml You can bind and Write in this way
<ListView Name="GroupList" ItemSource={Binding Path=GroupList}>
</ListView>
<ListView Name="StudentList" ItemSource={Binding Path=SelectedItem.StudentList,ElementName=GroupList}>
</ListView>
This you help you... ;)