In a Universal Windows Platform app a ContentThemeTransition can be applied to a ContentControl to animate the appearance of a new child control.
Is there a way to get the same visual behavior (animation) when simply changing the DataContext on the existing child control (rather that creating a new child control instance each time, which seems wasteful)?
Related
I am new to UWP app development and want to understand how xaml control is rendered in the UWP application. Which is the class that implements the rendering logic? And is that code open source? Also, when I create a new custom control, do I need to take care of rendering myself?
How is xaml control rendered in UWP application?
This is a big topic, for understanding this, we need to know UI Framework Layering. Windows.UI.XAML-> Windows.UI.Composition-> DirectX Family.
Derive from official document, The Visual layer provides a high performance, retained-mode API for graphics, effects and animations, and is the foundation for all UI across Windows devices. You define your UI in a declarative manner and the Visual layer relies on graphics hardware acceleration to ensure your content, effects and animations are rendered in a smooth, glitch-free manner independent of the app's UI thread.
And is that code open source?
Currently, the UWP open source controls are WinUI. You could find the base custom control build logic.
do I need to take care of rendering myself
The rendering is very low level, if you just custom control that inherit Control class, you have no need to care about the rendering process, you just need to build the interface in the target templated style. and add specific dependency property in the code behind. For more detail please refer to Templated Control document.
A Grid UIElement in winrt is receiving the GotFocus and LostFocus events, which are useful - but apparently Focus() is not a method available to Grid. How can the element be capable of having focus but not be capable of setting it? I am trying to restore keyboard focus to the main Grid of the app's UI when it is lost due to other interactions. Does anyone know how one might programmatically restore focus to a Grid that has just reported losing it? Thanks.
When I use a Button control in DataTemplate for ListView (UWP app), Drag-and-Drop of ListView items doesn't work. If I use containers like StackPanel, RelativePanel or Grid, instead of Button control, everything works fine. I would prefer the Button control as a container, because I like its mouse Hover effect on ListView items. I can do something similar for StackPanel, etc, with a custom hover effect by using a combination of Style and Behavior programming but trying to avoid this route (too involved).
Can I do something to the Button control so that it gives me the hover and also responds to the Drag-and-Drop event when part of a ListView DataTemplate?
I am also curious what specifically makes the Button suppress the Drag-and-Drop of ListView items.
The Button is capturing the pointer which cause the pointer click event not be bubble up to the ListViewItem which cause the Drag&Drop to start.
You can take a look at ReleasePointerCapture method which will release the pointer capture allowing other item to capture it.
You will need to create a new class which extends the default Button class and override for example the OnPointerPressed method to choose the logic between the drag&drop and the click on the button.
I'm porting a Windows Phone 8 app to Windows 8 and I have a scenario where the user taps an item in my list control / grid view and I want to play an "activation" animation on the item, wait for the animation to complete, and then navigate away from the page.
On Windows Phone, I used DataTriggers in one case, and in another I used VisualTreeHelper to iterate through the view and find the VirtualizingStackPanel and then the actual item and then accessed it directly to invoke the storyboard...
Neither appears to work in this case and also seems that DataTriggers are not supported in winrt (DataTrigger in WinRT?).
I'd like to do the right thing here. I've seen suggestions that visual states can be used, but it is not clear how in this case.
Any help much appreciated.
Thanks
There are two ways I would go about this, though neither is particularly pretty.
Method A
Create a custom control that will act as each GridView item and place it in the GridView's ItemTemplate.
<GridView>
<GridView.ItemTemplate>
<DataTemplate>
<mynamespace:MyControl/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Then, in MyControl's constructor, attach a handler to the Tapped event, and in that handler you can perform your animation. The animation can be defined in MyControl.xaml. MyControl should also expose an event for when the animation is complete
public event EventHandler SelectedAnimationComplete;
and fire it when your custom storyboard completes. The page hosting the GridView can attach to MyControl's custom event to perform the navigation.
...
<mynamespace:MyControl SelectedAnimationComplete="selectedAnimationComplete"/>
...
Method B
On the GridView, set SelectionMode to None, IsItemClickEnabled to true, and attach a handler to the ItemClick event. Inside the handler, you can use
(sender as GridView).ItemContainerGenerator.ContainerFromItem(e.ClickedItem)
to get the GridViewItem, and then dig down the visual tree with VisualTreeHelper.GetChild. In your ItemTemplate, the root visual (likely a Grid) can have your animation placed in its Resources collection. Dig down the visual tree until you find the ItemTemplate's root grid, get the animation from its Resources collection, attach a completion handler to it, and run it. You can perform your navigation in the completion handler.
There's no treeview control in win rt, anyone know how to create a treeview user control? Any control should I inheritant?
Navigation by hierarchical structure is better visualize with ListView in winrt. You need to display a list of nodes, when user touches a node, it should display ListView with sub nodes and button back.
But you can implement own control TreeView (that looks like WPF or Silverlight TreeView). You need to derive from ListBox and ListBoxItem controls, and add indent for subnodes at PrepareContainerForItemOverride() method.