为 WPF 应用程序使用加载指示器

Jum*_*mmi 4 c# wpf nuget-package

我对 WPF 比较陌生,我想添加一个加载指示器。我发现https://github.com/100GPing100/LoadingIndicators.WPF有一些很好的预制加载指示器,我为它安装了 NuGet 包,但我很难将它们实现到我的窗口。

所以我加了

<Window ...
    xmlns:loadin="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
    ...
>

Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将加载指示器之一添加到我的网格时,我在动态资源上收到错误

<Grid x:Name="TagLoadingIndicator" Panel.ZIndex="1">
    <loadin:LoadingIndicator SpeedRatio="{Binding SpeedRatio}" IsActive="{Binding IsDoubleBounceActive}" Style="{DynamicResource LoadingIndicatorDoubleBounceStyle}"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

无法解析资源“LoadingIndicatorDoubleBounceStyle”。

从我在其他网站上看到的内容来看,我正确地将它添加到 ResourceDictionary 中……而且我假设通过安装 NuGet 包,我已经定义了资源。我仍然可以运行该应用程序,但缺少指示器。我错过了什么?

谢谢

小智 6

该密钥存在于Styles.xaml文件中。因此,在您的资源中添加对它的引用。

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml"/>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
 </Window.Resources>
Run Code Online (Sandbox Code Playgroud)