I have problems to add a checkbox in the grid view header. When I add it appears like a ToString() of the checkbox.
My XAML is this:
<ListView x:Name="grdLotes" BorderThickness="0" Margin="0,0,20,0" >
<ListView.View>
<GridView AllowsColumnReorder="False" ColumnHeaderToolTip="Lotes">
<GridViewColumn Width="70">
<CheckBox></CheckBox>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="NĂºmero" Width="70"/>
<GridViewColumn Header="Tipo" Width="Auto"/>
<GridViewColumn Header="Comentario" Width="Auto"/>
<GridViewColumn Header="Movimientos" Width="80"/>
</GridView>
</ListView.View>
</ListView>
This is what shows:
Any idea how to solve this?
I tried to add into <GridViewColumn.Header> but is the same
Related
Hi I am using a TextBox inside a GridView column cell.
I am correctly able to place and bind the data for the TextBox in the 'Parameter' column.
<ListView Margin="5"
ItemsSource="{Binding Variables}"
Grid.Column="0"
Grid.Row="1"
Width="570">
<ListView.View>
<GridView>
<GridViewColumn Header="Type" Width="40"/>
<GridViewColumn Header="Parameter" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding ParameterName}"
Padding="0"
Margin="0"
Width="Auto"
HorizontalContentAlignment="Stretch"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Expression" Width="80"/>
<GridViewColumn Header="Value" Width="50"/>
<GridViewColumn Header="Default Value" Width="80"/>
<GridViewColumn Header="Value Type" Width="80"/>
<GridViewColumn Header="Show in UI" Width="80"/>
<GridViewColumn Header="Description" Width="80"/>
</GridView>
</ListView.View>
</ListView>
I want such that the TextBox width correctly adapts to the width of the 'Parameter' column, even when I try to resize the columns.
I have tried setting the Width and HorizontalContentAlignment properties of TextBox but was not succesful.
Right now it looks like as below:
Can anyone suggest how I can achieve this behavior?
You can add an item container style for ListViewItem that sets the HorizontalContentAlignment to Stretch. You can remove the HorizontalContentAlignment attribute from the TextBox.
<ListView Margin="5"
ItemsSource="{Binding Variables}"
Grid.Column="0"
Grid.Row="1"
Width="570">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Type" Width="40"/>
<GridViewColumn Header="Parameter" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding ParameterName}"
Padding="0"
Margin="0"
Width="Auto"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Expression" Width="80"/>
<GridViewColumn Header="Value" Width="50"/>
<GridViewColumn Header="Default Value" Width="80"/>
<GridViewColumn Header="Value Type" Width="80"/>
<GridViewColumn Header="Show in UI" Width="80"/>
<GridViewColumn Header="Description" Width="80"/>
</GridView>
</ListView.View>
</ListView>
I used list view with a single column, I would like this column with the same size list view with.
I mean Just one column fill the all with of the list view.
I tried this but didn't work...
<ListView Grid.Row="1" Grid.Column="1" x:Name="LvErrorList">
<ListView.View>
<GridView>
<GridViewColumn Width="{Binding ActualWidth, ElementName=LvErrorList}" Header="Status" DisplayMemberBinding="{Binding ErrorMessage}" />
</GridView>
</ListView.View>
</ListView>
I tried
<GridViewColumn Width="Auto" Header="Status" DisplayMemberBinding="{Binding ErrorMessage}" />
But some text are longer than the with of the ListView.
Becaues i don't know the user screen size i can't set max-width property.
Does anyone know how to fix this please?
You can try this way instead.
<ListView Grid.Row="1" Grid.Column="1" x:Name="LvErrorList">
<ListView.View>
<GridView>
<GridViewColumn Header="Status" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ErrorMessage}" Width="{Binding ElementName=LvErrorList,Path=ActualWidth}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I'm trying to add a custom user control of mine to a GridViewColumn and all I get is the ToString() output of that control.
my code:
<GridViewColumn Header="Progress" HeaderContainerStyle="{StaticResource MyHeaderStyle}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ProgressBar, Converter={StaticResource nullGuestImageConverter}}" Width="150" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I have tried before
<GridViewColumn HeaderContainerStyle="{StaticResource MyHeaderStyle}" Header="Status" DisplayMemberBinding="{Binding ProgressBar}" />
to no avail.
please help
My Xaml is:
<ListView Grid.Column="2" Grid.Row="2" Height="Auto" HorizontalAlignment="Left" Name="listViewResult" VerticalAlignment="Top" Width="Auto">
<ListView.View>
<GridView x:Name="gridResult">
<GridViewColumn Width="Auto" Header="Server" />
<GridViewColumn Width="Auto" Header="Value"/>
<GridViewColumn Width="Auto" Header="Availability"/>
<GridViewColumn Width="Auto" Header="Status"/>
</GridView>
</ListView.View>
</ListView>
And C# code is:
listViewResult.Items.Clear();
listViewResult.Items.Add(new { Server = "test1", Value = "ABX", Availability = "Yes", Status = "No"});
But the value is not getting display in Multi Column Listview
That's because you haven't specified anywhere what to display. You can either specify a GridViewColumn.CellTemplate or simply use DisplayMemberBinding to specify what property of the data object you want to display:
<ListView Grid.Column="2" Grid.Row="2" Height="Auto" HorizontalAlignment="Left" Name="listViewResult" VerticalAlignment="Top" Width="Auto">
<ListView.View>
<GridView x:Name="gridResult">
<GridViewColumn Width="Auto" Header="Server" DisplayMemberBinding="{Binding Server}" />
<GridViewColumn Width="Auto" Header="Value" DisplayMemberBinding="{Binding Value}"/>
<GridViewColumn Width="Auto" Header="Availability" DisplayMemberBinding="{Binding Availability}"/>
<GridViewColumn Width="Auto" Header="Status" DisplayMemberBinding="{Binding Status}"/>
</GridView>
</ListView.View>
</ListView>
The Header is just what shows up as the column heading. If all you want is the text associated with the data, you need to add a DisplayMemberBinding to actually put data in the column.
<ListView Grid.Column="2" Grid.Row="2" Height="Auto"
HorizontalAlignment="Left"
Name="listViewResult"
VerticalAlignment="Top" Width="Auto">
<ListView.View>
<GridView x:Name="gridResult">
<GridViewColumn Width="Auto"
Header="Server"
DisplayMemberBinding="{Binding Server}"/>
<GridViewColumn Width="Auto"
Header="Value"
DisplayMemberBinding="{Binding Value}"/>
<GridViewColumn Width="Auto"
Header="Availability"
DisplayMemberBinding="{Binding Availability}"/>
<GridViewColumn Width="Auto"
Header="Status"
DisplayMemberBinding="{Binding Status}"/>
</GridView>
</ListView.View>
</ListView>
The alternative is to create a CellTemplate with a DataTemplate, if you want more control over the appearance. For example:
<GridViewColumn>
<GridViewColumnHeader Content="Status" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="2,4">
<Image Source="Resources\SomePicture.ico"
Height="24"
Width="24"
VerticalAlignment="Center" />
<TextBlock Text="{Binding Status}"
Margin="2, 4"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I place the following statements in the second row of my grid in the xaml:
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
<ListView Name="listView" Margin="5" Grid.Row="1">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn DisplayMemberBinding="{Binding Path=DateTime}" Header="Date Time" Width="140"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Vehicle}" Header="Vehicle" Width="130"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=AlarmType}" Header="Alarm Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Direction}" Header="Direction" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Speed}" Header="Speed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Alarmed}" Header="Alarmed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=LoadType}" Header="Load Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Status}" Header="Status" Width="110"/>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</Grid>
I binded the listView.ItemSource to an ObservableCollection defined in the code to populate data to the list. When the number of items added to the GridView exceeded the listview height, the vertical scroll bar did not appear as i specified in the XAML. What did I do wrong? Your input is greatly appreciated. Thank you.
It works for me:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
<ListView Name="listView" Margin="5" Grid.Row="1">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn DisplayMemberBinding="{Binding Path=.}" Header="Whatever" Width="140"/>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</Grid>
</Window>
However, the ListView control template contains a ScrollViewer already such that the ScrollViewer will appear inside the ListView as and when needed. Why do you need to wrap it in another?
See that the margins and paddings are correct. The scrollbar can be behind something.
Put the exterior container height with a fixed value, It can be stretching the listview so it will never show the scrollbar.
HTH
Try this code:
ListView listView = new ListView();
listView.SetValue(Grid.RowProperty, 1);
listView.SetValue(Grid.ColumnProperty, 1);
MainGrid.Children.Add(listView);
No need of using ScrollViewer. Just remove the ScrollViewer and use only the ListView and try.
ListView listView = new ListView();
listView.SetValue(Grid.RowProperty, 1);
listView.SetValue(Grid.ColumnProperty, 1);
MainGrid.Children.Add(listView);
No need of specifying the width and height for the listview.
<Grid x:Name="MainMenuButtonGrid">
<StackPanel Margin="50,0,0,0">
<TextBlock Text="Please select any employee" Foreground="Wheat"/>
<ListView x:Name="listEmployeeDetail" SelectedValuePath="EmployeeID">
<ListView.View>
<GridView>
<GridViewColumn Header="EmployeeName" Width="100" DisplayMemberBinding="{Binding EmployeeName}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Grid>
You can simply use the MaxHeight property to constraint your listview to a specific height and the scrollbar will appear automaticly.
For example :
<ListView Name="listView" Margin="5" Grid.Row="1" MaxHeight="300">
<ListView.View>
<GridView AllowsColumnReorder="True">
<GridViewColumn DisplayMemberBinding="{Binding Path=DateTime}" Header="Date Time" Width="140"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Vehicle}" Header="Vehicle" Width="130"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=AlarmType}" Header="Alarm Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Direction}" Header="Direction" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Speed}" Header="Speed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Alarmed}" Header="Alarmed" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=LoadType}" Header="Load Type" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Status}" Header="Status" Width="110"/>
</GridView>
</ListView.View>
</ListView>