So far i have been working with listview without any problem. I have been able to pass multiple columns and fill them with images, text etc. I decided to do the same thing with a listbox but things there got complicated.
In a listview i do the following :
<DataTemplate x:Key="ImageTemplate" >
<Image x:Name="FavoriteImageList" Tag="{Binding tagger}" Width="12" Height="12" Source="{Binding ImageSource}" MouseLeftButtonDown="FavoriteImageList_MouseLeftButtonDown"/>
</DataTemplate>
<ListView x:Name="Citys">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
<GridViewColumn Width="90" Header="Image" CellTemplate="{StaticResource ImageTemplate}"/>
<GridViewColumn Width="178" Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="178" Header="City" DisplayMemberBinding="{Binding City}"/>
<GridViewColumn Width="140" Header="Author" DisplayMemberBinding="{Binding Author}"/>
</GridView>
</ListView.View>
</ListView>
And i fill columns like this :
foreach(var fav in Favorites)
{
Citys = new List<ACity>()
{
new ACity() {tagger = Name ,ImageSource = ImageSource ,Name= Name, Author= Author, City = City}
};
ListBox.Items.Add(Citys);
}
If I do this in a listbox, it will fill with (Collection).
Is there a way to do this in a listbox, passing images buttons strings in a listbox row?
See the example from the MSDN ItemsControl.ItemTemplate
<ListBox Width="400" Margin="10"
ItemsSource="{Binding Source={StaticResource myTodoList}}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=TaskName}" />
<TextBlock Text="{Binding Path=Description}"/>
<TextBlock Text="{Binding Path=Priority}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
It should be pretty straight forward to match with your example.
Related
I have a list view with a ton of data and any time I go to scroll / click somewhere on the screen it always takes a few seconds to react. I tried setting the list view to use virtualization but can't seem to get it to work.
I have tried this and this. Not sure if I am doing something wrong or not understanding how the virtualization works?
I do have a lot of styling / added grid view behaviors for my listview. If you have any suggestions please let me know!
What I Have Tried
I have tried removing the CollapseableCollumnBehavior from the list view. Had no change.
Removed all my font styles. Had no change.
Reduced the number of columns. Had a small change but still very unresponsive.
Turned off IsSyncronizedWithCurrentItem. Had no change.
Item Source
My item source is just an observable collection.This is how I load data into it.
private void LoadAllData()
{
using (var uow = _unitOfWorkFactory.Create())
{
foreach (var rule in _ruleRepository.GetAllRulesInCheckProcess())
{
AllRulesInCheckProcess.Add(rule);
}
}
}
XAML:
I took out a lot of my styling and added column behaviors from the xaml to simplify the code.
<ListView SelectedValue="{Binding SelectedRule}"
IsSynchronizedWithCurrentItem="True"
Grid.Column="0"
MinHeight="150"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
ScrollViewer.IsDeferredScrollingEnabled="True"
ItemsSource="{Binding AllRulesInCheckProcess}"
MaxHeight="300"
ScrollViewer.HorizontalScrollBarVisibility="Visible">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Description}" Width="auto">
<GridViewColumnHeader Content="Description">
<GridViewColumnHeader.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBox Height="25"
FontSize="{StaticResource FontSizeSmall}"
Text="{Binding ElementName=RulesInCheckProgressPage, Path=DataContext.DescriptionFilter}"
Tag="Filter Description"/>
<TextBlock Text="Description"/>
</StackPanel>
</DataTemplate>
</GridViewColumnHeader.ContentTemplate>
</GridViewColumnHeader>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding LaunchDate,StringFormat=MM/dd/yy}"
Width="auto">
<GridViewColumnHeader Content="Launch Date">
<GridViewColumnHeader.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBox Height="25"
FontSize="{StaticResource FontSizeSmall}"
Tag="Filter Launch Date"
Text="{Binding ElementName=RulesInCheckProgressPage, Path=DataContext.LaunchDateFilter}"/>
<TextBlock Text="Launch Date"/>
</StackPanel>
</DataTemplate>
</GridViewColumnHeader.ContentTemplate>
</GridViewColumnHeader>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding AddedDate,StringFormat=MM/dd/yy}" Width="auto">
<GridViewColumnHeader Content="Added Date">
<GridViewColumnHeader.ContentTemplate>
<DataTemplate>
<StackPanel>
<TextBox Height="25"
FontSize="{StaticResource FontSizeSmall}" Tag="Filter Added Date"
Text="{Binding ElementName=RulesInCheckProgressPage, Path=DataContext.AddedDateFilter}"/>
<TextBlock Text="Added Date"/>
</StackPanel>
</DataTemplate>
</GridViewColumnHeader.ContentTemplate>
</GridViewColumnHeader>
</GridViewColumn>
</GridView>
</ListView.View>
UPDATE
So through doing some more research it appears I may need to take a look at data virtualization instead of UI virtualization. Does anyone know of any up to date data virtualization code?
We are working on a ListView (C# WPF) and we didn't found how bind a list of items in columns, with each item containing itself a list of items with the same columns.
Let's illustre this in an example :
!
We got an observable collection on objects with parameters (name, etc.) and each object contain another observable collection of objects with the sames parameters (exept they haven't a list). So we want to list it in a ListView but we can't figure how !
We do not know enough ListView to implement this structure, some advices ?
Thanks in advance
I think the best way is :
XAML :
<Window.Resources>
<DataTemplate x:Key="gridViewSecondCellTemplate1">
<StackPanel Width="100">
<TextBlock Text="{Binding Content}" FontSize="15" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="gridViewCellTemplate1">
<StackPanel Width="100">
<TextBlock Text="{Binding Title}" FontSize="15" />
<ListView ItemsSource="{Binding MySecondSource}>
<ListView.View>
<GridView>
<GridViewColumn Header="{Binding Subtitle}" CellTemplate="{StaticResource gridViewSecondCellTemplate1}"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</DataTemplate>
</Window.Resources>
<ListView ItemsSource="{Binding MySource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Col 1" Width="100" CellTemplate="{StaticResource gridViewCellTemplate1}"/>
</GridView>
</ListView.View>
</ListView>
I didn't try this code. Try it, and say me if it is OK.
This is the XAML:
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=ScenarioName}" Header="Scenario Name" />
<GridViewColumn DisplayMemberBinding="{Binding Path=ScenarioType}" Header="Scenario Type" />
<GridViewColumn Header="Well names" Width="175">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<ItemsControl ItemsSource="{Binding Path=Wells}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<!--<TextBlock Text="{Binding}"/>-->
<Button Width="60" Margin="0 0 0 3">Test 1</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=StartPeriod}" Header="Start period" />
<GridViewColumn DisplayMemberBinding="{Binding Path=EndPeriod}" Header="End period" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Lagged}" Header="Lagged" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Detrended}" Header="Detrended" />
<GridViewColumn DisplayMemberBinding="{Binding Path=MinimumMonths}" Header="Length of continuous months" />
<GridViewColumn DisplayMemberBinding="{Binding Path=CorrelatedWells}" Header="Correlated wells" />
<GridViewColumn Header="Excluded Wells">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<ItemsControl ItemsSource="{Binding Path=ExcludedWells}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
And it looks like:
http://tinypic.com/view.php?pic=xpse8n&s=6
The questions is whether there is an easy to group the "Test1" buttons under Well names(in groups of,let say, 5 items) because the volume of well names can be quite big and neither horizontal nor vertical wrapping helps.
many thanks,
elias
Well you can always add a new property to your ViewModel
public IEnumerable<Well> SomeWells
{ get { return Wells.Take(5); }
and change your ItemsSource binding to use this instead.
Example here on MSDN
You could use a ListBox to let the user scroll through the buttons like:
<GridViewColumn Header="Well names" Width="175">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Button></Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I'm not 100% sure of what you're asking, but it sounds like you want something like 5 buttons in a row, and automatically wrapping to the next row every 5 buttons.
To make it work with a WrapPanel, you should give your panel a Width that is 5x with width of your buttons so it will draw 5 of them, then wrap to the next line
<ItemsPanelTemplate>
<WrapPanel Width="300" Orientation="Vertical"/>
</ItemsPanelTemplate>
Another alternative if you don't know your Button width ahead of time is to use a UniformGrid with 5 Columns. I think you also need to set the Row count to something larger than you ever expect your collection to be
<ItemsPanelTemplate>
<UniformGrid Columns="5" Rows="100" />
</ItemsPanelTemplate>
Another alternative for defining the Row count is to expose a property in your data model that contains the number of rows you'll need, and binding the Rows property to it.
<ItemsPanelTemplate>
<UniformGrid Columns="5" Rows="{Binding RowCount}" />
</ItemsPanelTemplate>
I can't remember if UniformGrid.Rows is a DependencyProperty or not, but if not then you can create an AttachedProperty instead that you can bind to and that will modify the UniformGrid.Rows property (for an example, see this code for Attached Properties for a Grid's Rows and Columns)
I had created the listview in below manner
using grid view init;
i need that when mouseover on the gridview item i need to get that username details in the popup window , i am able to generate the popupwindow
except that Hover username in the listview
this is my sample code so please try to provide this information
<ListView AlternationCount="2" removed="#FFB6CCD8" Canvas.Left="15" Canvas.Top="77" FontSize="13" Height="43" IsSynchronizedWithCurrentItem="True" ItemContainerStyle="{DynamicResource ListViewItemContainerStyle}" ItemsSource="{Binding}" Name="checkedListView1" SelectionMode="Single" TabIndex="2" Width="269" ItemTemplate="{StaticResource ItemDataTemplate}"
SelectionChanged="checkedListView_SelectionChanged" MouseEnter="checkedListView1_MouseEnter" MouseMove="checkedListView1_MouseMove">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=empid}" Header="CardID" Width="1" />
<GridViewColumn DisplayMemberBinding="{Binding Path=username}" Width="200" />
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="/WPF.Themes.Demo;component/Images/Status-user-online.ico" Width="20" Height="20"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
here i am using the listview in the Gridview manner , so please try to provide the Information to get the Username which was presented in the Gridviewcolumn when mouse cursor Hover in the listview
Thank you.
I am trying to bind a Dictionary property stored in a EffectViewModel inside an ObservableCollection, but it appears as "(Collection)" in the column I want to see as checkboxes.
Xaml for the GridViewColumn is this:
<GridViewColumn
Width="100"
Header="GPU"
DisplayMemberBinding="{Binding ShaderSupport}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="0"
HorizontalAlignment="Center"
IsChecked="{Binding Value}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
ShaderSupport is of type Dictionary<ShaderType, bool> where I just want to read in the bool value for ShaderType.GPU for this GridViewColumn.
Any ideas?
EDIT: Using this shows me the bool value as string, so I am in the right path I think:
DisplayMemberBinding="{Binding ShaderSupport[GPU]}">
Try this:
<GridViewColumn
Width="100"
Header="GPU">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="0"
HorizontalAlignment="Center"
IsChecked="{Binding ShaderSupport[CPU]}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>