WPF ListView virtualization in a ScrollViewer - c#

I have a requirement which is to display a user information at top of the page and a ListView of images will follow it, and I've wrote following code (it's a pseudocode but I think it's enough to explain what I've done):
<ScrollViewer>
<StackPanel>
<Grid>
<!-- User Information Part -->
</Grid>
<ListView>
<!-- Images Part, This is a custom virtualized ListView, it's ItemsPanel is a custom VirtualizingWrapPanel -->
</ListView>
</StackPanel>
</ScrollViewer>
But in this scenario, the VirtualizingWrapPanel (by which has been tested on another individual ListView without an explicit ScrollViewer declaration and it works correctly) and the virtualization of ListView won't work because the desired height of ScrollViewer is positive infinity and all the items in the ListView will be expanded and rendered, I wonder whether there is a way that can make the ListView in ScrollViewer being virtualizable? Thanks

You can't virtualize a list that has all elements being rendered (because of the StackPanel),
A workaround that will work for you: you need a single ListView. With the first row customized to display the User Information Part, and all other rows displaying images.

Related

How to virtualize data in simple stackpanel in Windows Phone application

I have created a list with ScrollViewer and stackpanel. I am adding user control to this stackpanel from codebehind.
I want to virtualize data that I can improve the performance of my application.
How can i achieve this?
I cann't use Listbox because I am adding user control as DataItems and each user control have a different width and height.. Please suggest how to implement that
Code:
XAML
<ScrollViewer>
<StackPanel x:Name="stckPnlComponentsLst" Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityInvertedConverter}}" Orientation="Vertical">
</StackPanel>
</ScrollViewer>
C#
for (int count = 0; count < countItems; count++)
{
stckPnlComponentsLst.Children.Add(new ChannelNewsLstControl(ViewModel.ComponentData[count], false, false));
}
I don't see any case in which using a StackPanel inside a ScrollViewer is a good idea.
You should not do that.
There are 2 controls to do what you want, ListBox and ListView.
If you really want to stick with a stackpanel inside a ScrollViewer, just replace your StackPanel, by a VirtualizingStackPanel. But again, you should NOT be doing that.
Use a ListBox instead. Check the sample here. For example, define ListBox in a xaml
<ListBox x:Name="MyList">
and then in codebehind
var MyListData = new List<ChannelNewsLstControl>();
MyListData.Add(new ChannelNewsLstControl {name = "MyFirstChannelName});
MyList.ItemsSource=MyListData;
If you have really lots of items, i'd recommend to use Telerik's DataBoundListBox as it is much faster than a normal ListBox (at least, for wp7) and supports virtualization and async loading. Sample would be pretty the same, as component is inherited ListBox and adding own features mentioned before.
EDIT: final answer:
Try to put a grid inside of your ItemTemplate and set its RowDefinition.Height = "Auto". See some details here

How to arrange the buttons vertically in RibbonControlGroup (wpf)

I have RibbonControlGroup with a few buttons.
<r:RibbonControlGroup>
<r:RibbonToggleButton Label="button1"/>
<r:RibbonToggleButton Label="button2"/>
</r:RibbonControlGroup>
On Ribbon buttons are arranged horizontally. Like (button1|button2).
How to arrange the buttons vertically?
I know, that I'm late to party, but may be this will help someone.
Since the RibbonControlGroup is an ItemsControl, the right way to go is to replace ItemsPanel like this:
<r:RibbonControlGroup>
<r:RibbonControlGroup.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</r:RibbonControlGroup.ItemsPanel>
<!-- Group items are listed below: -->
<r:RibbonToggleButton Label="button1"/>
<r:RibbonToggleButton Label="button2"/>
</r:RibbonControlGroup>
This approach conceptually differs from #Sajeetharan's answer, because he creates a group with a single child - StackPanel, while my sample still is an equivalent of the code, posted in the question: here's a group with two children of type RibbonToggleButton.
The difference will be meaningful with data binding scenarios, when items of group be populated dynamically through data binding expression.
You can keep these controls in a container and set its Orientation property to "Vertical"
For e.g. using StackPanel as a container
will place the buttons vertically
Use StackPanel and change the orientation to Vertical ,
<r:RibbonControlGroup>
<StackPanel Orientation="Vertical">
<r:RibbonToggleButton Label="button1"/>
<r:RibbonToggleButton Label="button2"/>
</StackPanel>
</r:RibbonControlGroup>

How to access child textbox inside cell on RadGridView

I'm using a telerik RadGridView which is pretty much the same thing as a normal DataGrid in WPF. In my gridview.columns I have a GridViewDataColumn which then allows me to put a celltemplate then a datatemplate and then allow me to put different controls within a grid. I have a combobox and a textbox(only one shows at a time based on visibility property). The problem I'm having is the tab system is kind of weird and doesn't work right. When I tab to a cell in the column above, my combobox nor my textbox ever gets focus. In fact the cell turns completly white. So I was wondering how (in code behind) can I detect when a user tabs in this particular cell and manually set focus to these child elements inside this cell on the selected row?
<telerik:GridViewDataColumn x:Name="MyDataColumn" Focusable="True" GotFocus="MyDataColumn_GotFocus_1" Header="Header1" Width="250">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Textbox x:name="MyTextbox" Visibility="{Binding IsTextbox}"/>
<Combobox x:name="MyCombobox" Visibility="{Binding IsCombo}"/>
</Grid>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
*Basically, how can I gain access to one of those child controls inside this GridViewDataColumn in code behind so that I can set focus to it? Thanks so much for any advice.
Probably the most straight forward answer to your question can be found by reading the answer to the Access items inside the DataTemplate in WPF post.
However, it may be worth reading the correct answer in this Access Elements inside a DataTemplate… How to for more than 1 DataTemplate? post also.

How to make ListView items arrange in grid format

I want to display a list of items in a table like format. The format is fluid such that if a user resizes then more or less items will display on a row. I want to replicate how floated divs display within a container.
How do I do this in WPF?
So far I can get the items to display in a vertical format but cant figure out what to do next. P.s. for now I am hard coding the items whilst I debug, but I will bind it to a list at some point.
<ListView>
<ListViewItem Width="244">
<local:ScheduledRecordingView />
</ListViewItem>
<ListViewItem Width="244">
<local:ScheduledRecordingView />
</ListViewItem>
</ListView>
Surely been asked before, please search before asking.
Just make the ItemsPanel a WrapPanel. If you don't create a specific View (not necessary here) you should use a ListBox or if you don't need selection either an ItemsControl.

WPF - Prevent Autoresize of ListBox on new Databinding?

I currently have a window with a ListBox within in. The ListBox shows the results from a search.
The problem I currently have is that when a search is performed and enough items are added to the ListBox, the ListBox expands vertically and forces the form to expand vertically as well.
I know I can fix this with a maxheight, but I don't want to limit the size of the form to the user, only to the program at runtime.
Is there a way I can tell the ListBox to not automatically expand or only expand when the user resizes the form?
My apologies... I've sorted out the problem. I'd mistakenly set Window.SizeToContent = "Height".
Problem solved.
Just put it in a Grid. Unless the window is set to automatically size (SizeToContent="..."), then this should work.
<Grid>
<ListBox x:Name="lstSomeData"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Grid>

Categories