WinUI 3 XAML创建AnimatedIcon报错:Source属性不支持AnimatedFindVisualSource类型
问题:AnimatedIcon.Source不支持AnimatedFindVisualSource类型的错误原因
按照文档尝试添加动画按钮时,Visual Studio提示导入模块xmlns:animatedvisuals="using:ABI.Microsoft.Microsoft.UI.Xaml.Controls.AnimatedVisuals",但导入后出现错误:
XLS0504 The "Source" property does not support values of type "AnimatedFindVisualSource".
我的代码:
<?xml version="1.0" encoding="utf-8"?> <Window x:Class="MyApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:MyApp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:animatedvisuals="using:ABI.Microsoft.Microsoft.UI.Xaml.Controls.AnimatedVisuals" mc:Ignorable="d" Activated="Window_Activated"> <Grid> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center"> <Button x:Name="myButton" Click="myButton_Click">Click Me</Button> <Button PointerEntered="Button_PointerEntered" PointerExited="Button_PointerExited" Width="75"> <AnimatedIcon x:Name="SearchAnimatedIcon"> <AnimatedIcon.Source> <animatedvisuals:AnimatedFindVisualSource/> </AnimatedIcon.Source> <AnimatedIcon.FallbackIconSource> <SymbolIconSource Symbol="Find"/> </AnimatedIcon.FallbackIconSource> </AnimatedIcon> </Button> </StackPanel> </Grid> </Window>
错误原因:
- 引用了错误的命名空间:
ABI.Microsoft.Microsoft.UI.Xaml.Controls.AnimatedVisuals是系统内部的ABI(应用二进制接口)命名空间,仅用于底层交互,不允许开发者直接使用。正确的命名空间应为xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals",去掉前缀ABI.即可。 - 依赖库配置问题:
AnimatedFindVisualSource属于WinUI 3控件库,需确保项目已正确安装并引用Microsoft.UI.Xaml(WinUI 3)包,且项目类型为WinUI 3兼容的应用(如Desktop WinUI 3应用、集成WinUI 3的UWP项目)。
内容的提问来源于stack exchange,提问作者Kureshik
相关产品推荐
相关产品推荐

