Double Animation item detection - c#

I'm currently writing a marquee control for WPF. The control consists of an ItemsControl, with TextBlock as the DataTemplate element of choice. The ItemsControl is the target of a Double Animation, which manipulates the Canvas.Left property.
What I would like to do is create a "circular mode", which will allow the marquee to dynamically add an item to its' tail whenever the last item has scrolled into view. That way, the marquee will never appear empty.
How can I detect when a TextBlock has "scrolled" into view (effectively become visible) as a result of the animation?

It might work that you check whether the ItemControl's ActualWidth property is greater than the current Canvas.Left value of your TextBlock.
To get the change event, have a look at this SO: How do I handle Canvas.Top change event in WPF?
Maybe it is useful to keep a references to the last control that was added to the tail of your marquee, so that you can remove the event handler once the control is scrolled into view and attach the event handler to the TextBlock that is then added to the tail.
It would be nice to be able to draw something for a better understanding. If anything's unclear (technically or conceptually) ask, ask, ask... :)

Related

How to bring an element inside a list view item to the front of the entire app?

Using UWP XAML, I am trying to recreate this textbox UX from Postman whereby it pops up above all other elements in the app to display the full text: https://streamable.com/avrixo. I've almost fully recreated this UX, but I am having trouble bringing the textbox to the "front" of the app while the textbox is inside a listview.
What I have tried:
I have tried creating a UserControl for a custom text box with Canvas as its parent. Like this:
<Canvas>
<TextBox/>
</Canvas
I added some event handling to change the text wrapping and the Canvas.Zindex attached property of the textbox when the user focuses on it (I've tried setting the z-index to 1, 10, 100, and 1000000). However, I found that as the textbox expands vertically, it remains "behind" the listview item below it no matter what z-index I give it.
How can I bring the textbox inside a listview item to the "front" of the UI?
I don't think your problem is with z-index (per say) in this case. The problem here in the ListView is that each ListViewItem has it's own bounds, so the TextBox is being clipped by the bounding box of the item. You can double-check the bounding areas with the Visual Tree tools at least to confirm that's the issue.
If you don't want the ListViewItem to expand in size to match, I can see two options. When the user clicks to edit, you put a 'fake' TextBox (bound to the original in the ListView or the data item) either in 1) a Pop-up that you display or 2) in an overlay that's part of your page's XAML that has the textbox.
You can grab the selection state and cursor positions and such from the original textbox, and move focus to the new one and mirror that same state.
That's the approach I think I'd take.

Adding text to moving Ellipse in C# WPF

i have a program in C#, wpf.
i have a canvas and on the canvas exists many ellipses that are moving randomly.
Can i add text to each ellipse for example the position of the ellipse ???
Of course, create a user control. The xaml of that user control is a grid that contains your ellipse and your textbox that you set up like you want. Then define the PropertyChanged notifying properties you need, like X,Y, and maybe other text property. Then bind your user control's xaml (Canvas.Top/.Left) to your user control's properties, and you're done.

How VerticalOffset changes when Scrollable height changes while having list inside a list

I am making a WP7 app which has a Listbox of UserControls. Each UserControl has an ItemsControl and Button(for getting more results). On click of the button the ItemsControl items will be increased by 5 or 10.
Now on clicking on the GetMore button of any of the usercontrols except the first or last, there will be an increase in Scrollable height(Total height of the listbox) of the ListBox but the VerticalOffset(position of scrollbar from top) of the ListBox remains same. Now the problem I am facing is that the Vertical Offset is not absolute but relative to Scrollable Height. So the content being viewed till then will be changed basing on the new value of ScollableHeight.
I want to know the relation between them, so that I can do some math and set the VerticalOffset value.
I have added some dependency properties on VerticalOffset and ScrollableHeight through which I can get the events when any of them is changed. Trying to use ScrollIntoView for readjusting the Vertical Offset
Any suggestions or corrections are highly appreciated.
I am not able to find the calculation. But what can be done is listbox can be replaced by a scrollviewer which has itemsControl inside it. But the disadvantage of this is virtualisation is disabled, so will need to check on this.
But, overall this is going to give a bad experience on using such a UserControl in Listbox. So using templated list box given in WP7 toolkit is an option but it is gonna hang a bit since ListBox is not optimized for multi templated virtualization. So I started showing writing listbox item template in such a way it contains all the possible layouts which will enabled from a condition.

C# WPF - Global ScrollViewer Mode

I have made some custom attached properties that enable me to create a "pop out" effect on any control.
It animates the width and/or height when a boolean DependencyProperty is toggled.
Is there a good way to set all ScrollViewer's scrollbar visibility inside the control to hidden during this effect? You can see some ugly scrollbars appear during the animation.
I would rather not have to traverse the visual tree at the start of the animation, and then do it again when the animation completes.
EDIT: Although an alternate solution would be nice, at this point I'd rather bind to a readonly attached property named IsAnimating to handle setting the scroll visibility.
Is there a global way to to this?
Instead of animating the width of the control itself, try fixing its width at the start of the animation and reparenting it into a grid, and animate the grid's width instead. The original visual wouldn't change size in its own little world, and no scroll bars would appear or change.

In a WPF ListView how can I prevent auto scrolling?

I have a WPF ListView which currently scrolls everytime I click on an item which is only partially visible. How can I keep the control from scrolling that item into view (instead simply selecting the partially visible one)? This behavior is very annoying when doing a drag from this control.
Thanks.
Added: I am looking for a solution to keep the control itself from scrolling when contents are clicked that the control believes are not fully visible. Often this is by a few pixels and the scroll is not necessary.
The items scroll into view because the default behavior on list item click is to call BringIntoView(). You can add an event handler for the RequestBringIntoView event and catch it before it bubbles up from the ListViewItems to the ScrollViewer. In your handler, check the bounds of the sender against the visible region and if you decide that you don't need to scroll, set the event's Handled flag to true.
Since I'm currently on the road, I cannot try this, but have you tried playing around with CanContentScroll, and/or wrapping the scrollable content into a Panel, as suggested by the ScrollViewer Overview on MSDN?
In the worst case, you might want to replace the ListView's ItemsPanel by a hacked ScrollViewer with a "fuzz" factor, e.g. by capturing the RequestBringIntoView event.
have you tried this approach?
just as an addon, I don't know how much you know about the subject, but here is a good place to read more about it.
added:
I just found that you can prevent the mouse wheel of scrolling as well.

Categories