I have ListView binding with my collection:
private List<MyData> Col;
ItemsSource="{Binding Col}"
I define this inside my ListView:
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Selected">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="cbSelect" IsChecked="{Binding SupportedVendors}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding ID}" Header="ID" Width="600"/>
</GridView.Columns>
</GridView>
</ListView.View>
Now i want channge my object bool value inside my Collcection once the user change the CheckBox.
I can i do that ? (i need it in code behaind)
Tag the object of your collection with the CheckBox, the on check /uncheck you can get the tag from the checkbox checked. Change the bool value in the object.
Related
I'm prrety new to wpf, and i try to make a GridView that inside ListView to response to double click on row in the view
I try to make this-
<ListView
ItemsSource="{Binding Products}">
<ListView.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding Test}" />
</ListView.InputBindings>
<ListView.View>
<GridView>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn
Header="ID"
DisplayMemberBinding="{Binding ID}" />
<GridViewColumn
Header="Name"
DisplayMemberBinding="{Binding Name}" />
<GridViewColumn
Header="Category"
DisplayMemberBinding="{Binding Category}" />
<GridViewColumn
Header="Price"
DisplayMemberBinding="{Binding Price}" />
</GridView>
</ListView.View>
<ListView />
when Test is an ICommand property in the view model.
But it's not responding to double click.
What am I getting wrong, and mabye there is another way?
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
I created list view with check box at column 1, but it's displaying only at header level and in rows i'm getting namespace name.
Here's the XAML code:
<ListView x:Name="ConfigurationFilesGrid" ItemsSource="{Binding ConfigurationFiles}"
SelectedItem="{Binding SelectedProgramFile}"
ScrollViewer.CanContentScroll="True"
PreviewMouseDoubleClick="ConfigurationFilesGrid_Reselect"
>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Header="{x:Static res:Resources.IDColNameTxt}" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="{x:Static res:Resources.TypeColHdr}" DisplayMemberBinding="{Binding DisplayType}" />
<GridViewColumn Header="{x:Static res:Resources.NameColNameTxt}" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="{x:Static res:Resources.MeterColNameTxt}" DisplayMemberBinding="{Binding MeterType}"/>
<GridViewColumn Header="{x:Static res:Resources.RateColNameTxt}" DisplayMemberBinding="{Binding RateDisplay}"/>
<GridViewColumn Header="{x:Static res:Resources.CommentColNameTxt}" DisplayMemberBinding="{Binding Comment}"/>
<GridViewColumn Header="{x:Static res:Resources.ModifiedDateColNameTxt}" DisplayMemberBinding="{Binding ModifiedDateTime}"/>
<GridViewColumn Header="{x:Static res:Resources.ProfileColNameTxt}" DisplayMemberBinding="{Binding Profile}"/>
</GridView>
</ListView.View>
</ListView>
And i'm getting list view like:
[](checkbox) ID Name Address
name 1 A X
name 2 B Y
But from above i'm getting checkbox only at header level not rows level so what change 'll reflect to checkbox from above xaml code.
Thanks for you help.
Nag
You've used the HeaderTemplate of the GridViewColumn, use the CellTemplate instead:
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I'm trying to create a Window with a ListView and an Area where details to the selected Object are displayed. The Listview displays items stored in an ObservableCollection(Of T) Collection. The items itself contain also an ObservableCollecton(Of T) Collection which should then be displayed in the details area in another ListView, accordingly to the selected item of the first ListView.
The Problem:
The InitializeComponent() throws an Exception (XAMLParseException).
Exception:
Set property 'System.Windows.Controls.GridViewColumn.DisplayMemberBinding' threw an exception.
InnerException:
Object of type 'System.String' cannot be converted to type 'System.Windows.Data.BindingBase'.
The Line- and ColumNumer of the Exception are Pointing at the <GridView> of my ListView (.View)
This is the First ListView
<ListView ItemsSource="{Binding Path=MyObjectCollection, Mode=OneWay}" SelectedItem="{Binding Path=Selected, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Name, Mode=OneWay}">
<GridViewColumnHeader Content="Name" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
And this is the second ListView
<ListView ItemsSource="{Binding Path=SelectedItem.MySubCollection, Mode=OneWay}">
<ListView.View>
<GridView> <!-- Thats the Line where the Exception is pointing at -->
<GridViewColumn Width="150" DisplayMemberBinding="Key">
<GridViewColumnHeader Content="Key" />
</GridViewColumn>
<GridViewColumn Width="150" DisplayMemberBinding="Value">
<GridViewColumnHeader Content="Value" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
So. How can I bind to the Collection Property of an Object could be nothing?
From the exception message the problem is with with your DisplayMemberBinding in the second listview. Because you have to provide a Binding expression instead of a string see MSDN. Like in your first listview:
<ListView ItemsSource="{Binding Path=SelectedItem.MySubCollection, Mode=OneWay}">
<ListView.View>
<GridView> <!-- Thats the Line where the Exception is pointing at -->
<GridViewColumn Width="150" DisplayMemberBinding="{Binding Path=Key}">
<GridViewColumnHeader Content="Key" />
</GridViewColumn>
<GridViewColumn Width="150" DisplayMemberBinding="{Binding Path=Value}">
<GridViewColumnHeader Content="Value" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>