How to detect if a ListView in WPF would need scrolling?
I have several items in a list view in WPF. I'm wanting to add some items to the next "page" when they reach beyond the viewing area. However, I don't want scrolling available. I disable the scrolling.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
I don't want scrolling at all, I only want to know if there are items beyond the scrolling. Currently I limit the list by number of items on the page, however my items are not same size nor would I know the size of the screen so this needs to be adjustable.
c# wpf listview wpf-listview
add a comment |
I have several items in a list view in WPF. I'm wanting to add some items to the next "page" when they reach beyond the viewing area. However, I don't want scrolling available. I disable the scrolling.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
I don't want scrolling at all, I only want to know if there are items beyond the scrolling. Currently I limit the list by number of items on the page, however my items are not same size nor would I know the size of the screen so this needs to be adjustable.
c# wpf listview wpf-listview
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Maybe you can change toScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use theIsVisibilityChanged
event.
– Roland Deschain
Nov 16 at 9:01
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56
add a comment |
I have several items in a list view in WPF. I'm wanting to add some items to the next "page" when they reach beyond the viewing area. However, I don't want scrolling available. I disable the scrolling.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
I don't want scrolling at all, I only want to know if there are items beyond the scrolling. Currently I limit the list by number of items on the page, however my items are not same size nor would I know the size of the screen so this needs to be adjustable.
c# wpf listview wpf-listview
I have several items in a list view in WPF. I'm wanting to add some items to the next "page" when they reach beyond the viewing area. However, I don't want scrolling available. I disable the scrolling.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
I don't want scrolling at all, I only want to know if there are items beyond the scrolling. Currently I limit the list by number of items on the page, however my items are not same size nor would I know the size of the screen so this needs to be adjustable.
c# wpf listview wpf-listview
c# wpf listview wpf-listview
edited Nov 16 at 21:45
asked Nov 15 at 22:36
Demodave
3,32842941
3,32842941
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Maybe you can change toScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use theIsVisibilityChanged
event.
– Roland Deschain
Nov 16 at 9:01
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56
add a comment |
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Maybe you can change toScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use theIsVisibilityChanged
event.
– Roland Deschain
Nov 16 at 9:01
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Maybe you can change to
ScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use the IsVisibilityChanged
event.– Roland Deschain
Nov 16 at 9:01
Maybe you can change to
ScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use the IsVisibilityChanged
event.– Roland Deschain
Nov 16 at 9:01
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56
add a comment |
1 Answer
1
active
oldest
votes
Although this is a solution and works, it doesn't appear to be good on performance need another answer.
In order to speed up performance I now
tempNumItemsPerPage = tempNumItemsPerPage -2;
1) Added an Event handler for the scrollchange in the constructor
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) Added the Event onto my listview
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3) Add the scrollchanged code
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
The only issue I have is it resets the page everytime seeing if the scrollbar is off [not visible to the eye].
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328848%2fhow-to-detect-if-a-listview-in-wpf-would-need-scrolling%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Although this is a solution and works, it doesn't appear to be good on performance need another answer.
In order to speed up performance I now
tempNumItemsPerPage = tempNumItemsPerPage -2;
1) Added an Event handler for the scrollchange in the constructor
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) Added the Event onto my listview
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3) Add the scrollchanged code
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
The only issue I have is it resets the page everytime seeing if the scrollbar is off [not visible to the eye].
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
add a comment |
Although this is a solution and works, it doesn't appear to be good on performance need another answer.
In order to speed up performance I now
tempNumItemsPerPage = tempNumItemsPerPage -2;
1) Added an Event handler for the scrollchange in the constructor
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) Added the Event onto my listview
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3) Add the scrollchanged code
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
The only issue I have is it resets the page everytime seeing if the scrollbar is off [not visible to the eye].
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
add a comment |
Although this is a solution and works, it doesn't appear to be good on performance need another answer.
In order to speed up performance I now
tempNumItemsPerPage = tempNumItemsPerPage -2;
1) Added an Event handler for the scrollchange in the constructor
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) Added the Event onto my listview
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3) Add the scrollchanged code
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
The only issue I have is it resets the page everytime seeing if the scrollbar is off [not visible to the eye].
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
Although this is a solution and works, it doesn't appear to be good on performance need another answer.
In order to speed up performance I now
tempNumItemsPerPage = tempNumItemsPerPage -2;
1) Added an Event handler for the scrollchange in the constructor
public ViewName()
{
InitializeComponent();
// Handler to add scroll change event
Items.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(Items_ScrollChanged));
Init();
}
2) Added the Event onto my listview
<ListView ScrollViewer.ScrollChanged="OrderItems_ScrollChanged">
3) Add the scrollchanged code
private void OrderItems_ScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs)
{
ScrollViewer scrollViewer = Extensions.WPFExtensions.GetChildOfType<ScrollViewer>(Items);
if (scrollViewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
{
GetItemsOnPage();
tempNumItemsPerPage--;
}
}
The only issue I have is it resets the page everytime seeing if the scrollbar is off [not visible to the eye].
public static class WPFExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
edited Nov 16 at 22:35
answered Nov 16 at 15:46
Demodave
3,32842941
3,32842941
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328848%2fhow-to-detect-if-a-listview-in-wpf-would-need-scrolling%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you show the entire XAML code?
– Dark Templar
Nov 16 at 6:15
Maybe you can change to
ScrollViewer.HorizontalScrollBarVisibility="Auto"
but change the width to zero or one. This way you could use theIsVisibilityChanged
event.– Roland Deschain
Nov 16 at 9:01
@RolandDeschain I thought about making the scrollbar match the background, but I think I like your idea better. Trying to look for a better solution.
– Demodave
Nov 16 at 14:10
Just for my general understanding. You really just want to know, if your "page" is full of items, right? Are the items of same size? You could add the size of the items and compare them to the listview size (+ maybe margin/padding).
– Roland Deschain
Nov 16 at 14:24
@RolandDeschain, the items are not of the same size. Is it possible to add all the sizes of the items and see if they are listview size what about padding margins?
– Demodave
Nov 16 at 16:56