问题
Microsoft has deprecated SlidableListItem in favour of SwipeControl. I tried SwipeControl using the XAML controls gallery - it does not let me swipe left and right with a mouse (I can using SlidableListItem). I think I need a touchscreen device for it to work.
So I'd like to continue using SlidableListItem despite having updated to the latest nuget packages.
I've copied the code for SlidableListItem into my project from WindowsCommunityToolKit branch 4.0.0. I get this crash when I try to use the control:
System.TypeLoadException: Failure has occurred while loading a type.\r\n at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
(I successfully copied the code for the HamburgerControl into my project yesterday.)
回答1:
I tried to copy the source code of SlidableListItem, after paying attention to the following points, I successfully copied it:
- If you don't need
SwipeControl
, please delete the related code:- Do not copy the code of
SlidableListItemSwipeControlTemplate.xaml
- Delete the properties and callback methods related to
UseSwipeControlWhenPossible
in SlidableListItem.cs (such asOnUseSwipeControlWhenPossibleChanged
,OnSwipeControlValueChanged
,UpdateSwipeControlItems
, etc.) - In the
SledableListItem.cs
file, there are two places that refer to the resource file path, please modify it according to your own project structure (you can also delete the relevant code ifSwipeControl
is not needed)
- Do not copy the code of
- If you are migrating the code to your own control library, please remember to introduce
SlidableListItem.xaml
resource file in App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Controls/SlidableListItem.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
But in fact, SwipeControl
is a common control that UWP adapts to the operating habits of different platforms. On the desktop, we hold down the left mouse button and drag and drop is usually used to perform the transfer
operation instead of calling out the secondary menu (we usually right-click on the desktop).
Simulating touch screen operation experience in keyboard and mouse mode is sometimes not a pleasant thing. If you plan to adapt to the operation habits of multiple platforms, please refer to this document to add compound commands.
来源:https://stackoverflow.com/questions/62068607/cant-use-source-code-for-deprecated-control-slidablelistitem