6 Answers, 1 is accepted
Hello Scott ,
I understand your requirement. I can suggest the following. We can introduce a protected method OnScrollIntoVioew(int itemIndex) that you can use by inheriting from RadComboBox. You can see this implemented in the attached project. It uses custom built dlls and is only for proof of concept purposes. If we receive positive feedback from you on it, we will decide on adding this protected method for the official Release or some of the internal builds after it later this month.
Regards,
Petar Mladenov
Progress Telerik
Thats the idea. Is there a way to make it work with a virtualised ItemsPanelTemplate? I.e. to Mainpage.xaml add
<
UserControl.Resources
>
<
Style
x:Key
=
"longComboBoxItemsPanelTemplate"
TargetType
=
"local:CustomCombo"
>
<
Setter
Property
=
"ItemsPanel"
>
<
Setter.Value
>
<
ItemsPanelTemplate
>
<
VirtualizingStackPanel
/>
</
ItemsPanelTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
UserControl.Resources
>
and change the combo to
<
local:CustomCombo
x:Name
=
"combo"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Center"
Style
=
"{StaticResource longComboBoxItemsPanelTemplate}"
/>
Add some more lines to the data source:
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"a item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"b item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"c item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"d item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"e item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"f item"
+ i);
}
for
(
int
i = 0; i < 10; i++)
{
strings.Add(
"g item"
+ i);
}
Run and press 'd' and it jumps to the end
Hello Scott,
When using the VirtualizingStackPanel the Filtering feature of the RadComBox is not supported. Also, its highly recommended to set it to false because some unwanted 'scrollings' can happen in the drop down. I managed to achieve your scenario with the following code:
- set IsFilteringEnabled to False, added custom panel as itemsPanel
<local:CustomCombo x:Name="combo" VerticalAlignment="Center" IsFilteringEnabled="False" HorizontalAlignment="Center">
<local:CustomCombo.ItemsPanel>
<ItemsPanelTemplate>
<local:CustomVirtualizingStack />
</ItemsPanelTemplate>
</local:CustomCombo.ItemsPanel>
</local:CustomCombo>
- in CustomCombo class its is essential to get the stack panel and invoke a bring function
public class CustomCombo : RadComboBox
{
private ScrollViewer scroller;
private CustomVirtualizingStack stackPanel;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.scroller = GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
}
protected override void OnScrollIntoView(int itemIndex)
{
if (this.stackPanel == null)
{
this.stackPanel = (this.scroller.Content as ItemsPresenter).ChildrenOfType<CustomVirtualizingStack>().FirstOrDefault();
}
if (this.stackPanel != null)
{
this.stackPanel.BringIndex(itemIndex);
}
}
}
- the idea behind the custom bring function and the inheritance is to allow access to the protected method ScrollToVerticalOffset.
It was also very strange that it accepts a parameter which acts like index, although the method indicates that it uses vertical offset.
public class CustomVirtualizingStack : VirtualizingStackPanel
{
public void BringIndex(int index)
{
this.ScrollOwner.ScrollToVerticalOffset(index);
}
}
Please let me know if the suggested code applies well at your side.
Regards,
Petar Mladenov
Progress Telerik
Hi Scott,
Glad that the solution works for you. So to summarize, we will need to add the protected method OnScrollIntoView for some of our next internal builds and ServicePack. The official version R1 2020 will be released later today and won't include this method. I hope this plan is suitable for your project.
Regards,
Petar Mladenov
Progress Telerik
Hello Scott,
The protected OnScrollIntoView method will be available in the next internal build (next week).
Regards,
Petar Mladenov
Progress Telerik