[Solved/Workaround] Floating progress visualization with button control
-
I have created a progress unit control that show a progress in my WPF application and it looks like this: [https://pasteboard.co/peNn9PiguyNC.png\](https://pasteboard.co/peNn9PiguyNC.png) The way I have done this is adding a `ListView` in my main application view that has a higher ZIndex than the other controls. This essentially overlays all controls, but does not react hit tests and is not visible.
I have most of the WPF code here, but if you need it, I can post it This works as you can see from the picture. If you look at the picture, there is a close image which is implemented this way:
I would like to be able to click this button to close any progress unit, in case it blocks the users view of any controls beneath it. With my current implementation this is not possible as my `ListView` currently is marked with `IsHitTestVisible="False"`. That means all controls under it also ignores the hit test, even if I set the buttons `IsHitTestVisible` to true. That means the button cannot be clicked by the mouse. How can I make the button work on my progress unit and still have them floating? So far: - I have experimented with overriding the hittest of the listview, so I can ignore hittest in code but allow the button to be pressed. This did not work, but I am still looking into this. - I have tried fiddling with the ZIndex on the Button, but if the listview ZIndex is lower that the rest, then buttons inside it will of cause also be behind it, no matter the buttons ZIndex. Its a part of the ListView. - I have also looked into the Adorner layer. I find that this could probably work, but it will require a complete rewrite of the logic and as I understand it is not really what it is meant for and will be very complicated. Any suggestions is very welcome. I am 99% done, I just need the last little piece of the puzzle. Solution/Workaround So browsing some more and looking a bit into the links in the replies, I came up with a solution. I found it while browsing but to be honest i forgot where from. Anyway, the first thin
-
I have created a progress unit control that show a progress in my WPF application and it looks like this: [https://pasteboard.co/peNn9PiguyNC.png\](https://pasteboard.co/peNn9PiguyNC.png) The way I have done this is adding a `ListView` in my main application view that has a higher ZIndex than the other controls. This essentially overlays all controls, but does not react hit tests and is not visible.
I have most of the WPF code here, but if you need it, I can post it This works as you can see from the picture. If you look at the picture, there is a close image which is implemented this way:
I would like to be able to click this button to close any progress unit, in case it blocks the users view of any controls beneath it. With my current implementation this is not possible as my `ListView` currently is marked with `IsHitTestVisible="False"`. That means all controls under it also ignores the hit test, even if I set the buttons `IsHitTestVisible` to true. That means the button cannot be clicked by the mouse. How can I make the button work on my progress unit and still have them floating? So far: - I have experimented with overriding the hittest of the listview, so I can ignore hittest in code but allow the button to be pressed. This did not work, but I am still looking into this. - I have tried fiddling with the ZIndex on the Button, but if the listview ZIndex is lower that the rest, then buttons inside it will of cause also be behind it, no matter the buttons ZIndex. Its a part of the ListView. - I have also looked into the Adorner layer. I find that this could probably work, but it will require a complete rewrite of the logic and as I understand it is not really what it is meant for and will be very complicated. Any suggestions is very welcome. I am 99% done, I just need the last little piece of the puzzle. Solution/Workaround So browsing some more and looking a bit into the links in the replies, I came up with a solution. I found it while browsing but to be honest i forgot where from. Anyway, the first thin
Evilfish2000 wrote:
How can I make the button work on my progress bar, and still have the IsHitTestVisible="False" on the ListView?
You can't; if you set
IsHitTestVisible="False"
on an element, it applies to that element and all of its descendants, regardless of the hit test settings on the child elements. #680 – IsHitTestVisible Applies to All Child Elements | 2,000 Things You Should Know About WPF[^] https://stackoverflow.com/questions/12148286/how-can-you-set-ishittestvisible-to-true-on-a-child-of-something-where-its-set[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Evilfish2000 wrote:
How can I make the button work on my progress bar, and still have the IsHitTestVisible="False" on the ListView?
You can't; if you set
IsHitTestVisible="False"
on an element, it applies to that element and all of its descendants, regardless of the hit test settings on the child elements. #680 – IsHitTestVisible Applies to All Child Elements | 2,000 Things You Should Know About WPF[^] https://stackoverflow.com/questions/12148286/how-can-you-set-ishittestvisible-to-true-on-a-child-of-something-where-its-set[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I edited my question. For the original question, you are correct. I can't. I found that out and also found the same stackoverflow link you have posted. So my revised question, is now: How can I make the button work on my progress unit and still have them floating?
-
I have created a progress unit control that show a progress in my WPF application and it looks like this: [https://pasteboard.co/peNn9PiguyNC.png\](https://pasteboard.co/peNn9PiguyNC.png) The way I have done this is adding a `ListView` in my main application view that has a higher ZIndex than the other controls. This essentially overlays all controls, but does not react hit tests and is not visible.
I have most of the WPF code here, but if you need it, I can post it This works as you can see from the picture. If you look at the picture, there is a close image which is implemented this way:
I would like to be able to click this button to close any progress unit, in case it blocks the users view of any controls beneath it. With my current implementation this is not possible as my `ListView` currently is marked with `IsHitTestVisible="False"`. That means all controls under it also ignores the hit test, even if I set the buttons `IsHitTestVisible` to true. That means the button cannot be clicked by the mouse. How can I make the button work on my progress unit and still have them floating? So far: - I have experimented with overriding the hittest of the listview, so I can ignore hittest in code but allow the button to be pressed. This did not work, but I am still looking into this. - I have tried fiddling with the ZIndex on the Button, but if the listview ZIndex is lower that the rest, then buttons inside it will of cause also be behind it, no matter the buttons ZIndex. Its a part of the ListView. - I have also looked into the Adorner layer. I find that this could probably work, but it will require a complete rewrite of the logic and as I understand it is not really what it is meant for and will be very complicated. Any suggestions is very welcome. I am 99% done, I just need the last little piece of the puzzle. Solution/Workaround So browsing some more and looking a bit into the links in the replies, I came up with a solution. I found it while browsing but to be honest i forgot where from. Anyway, the first thin
You don't need to change the zorder to put it "on top"; you just span the whole grid and then position it the way you want and add it to the (XAML) visual tree last. Or put a canvas behind it for abolute positioning. The button can be placed anywhere relative to the progress "widget" using the same priciples. As for "hit testable", you can "swallow" clicks anytime it simpifies things. (e.Handled = true or false). (If you can "close" the widget, it begs the question: how do you open it. Maybe the button should be on a top or side "command bar": an enable / disable toggle).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I