为什么一个 Path 资源不能被多个 StaticResource 引用使用?

Why can a Path resource not be used by multiple StaticResource references?

拜托!谁能帮我解决这个问题: 我已经定义了一个由 Metro Studio 创建的路径图标。就像这样:

<Window.Resources>
    <!--ICO Resources-->
    <Path x:Key="CheckBoxOKICO" Data="M23.699997,8.8999939L26.099991,11.699997 13.099991,23.099991 5.8000031,14.599991 8.5999908,12.199997 13.5,17.899994z M1.6999969,1.6999969L1.6999969,30.300003 30.300003,30.300003 30.300003,1.6999969z M0,0L32,0 32,32 0,32z" Stretch="Uniform" Fill="#FF161616" Width="26" Height="26" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
        <Path.RenderTransform>
            <TransformGroup>
                <TransformGroup.Children>
                    <RotateTransform Angle="0" />
                    <ScaleTransform ScaleX="1" ScaleY="1" />
                </TransformGroup.Children>
            </TransformGroup>
        </Path.RenderTransform>
    </Path>

这是一个矢量图标: 我想在我的 WPF 中重用它 window UI:

       <!--Button1 is OK-->
    <Button x:Name="btnTaskItem1" Grid.Row="0">
        <Button.Content>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"  Width="220">
                <Viewbox Width="18" Height="18" Child="{StaticResource CheckBoxOKICO}"/>
                <TextBlock x:Name="txtTaskItem1" Margin="5,0"  Text="binding Task Item1"/>
            </StackPanel>
        </Button.Content>
    </Button>
    <!--Button2 is No OK-->
    <Button x:Name="btnTaskItem2" Grid.Row="1">
        <Button.Content>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"  Width="220">
                <Viewbox Width="18" Height="18" Child="{StaticResource CheckBoxOKICO}"/>
                <TextBlock x:Name="txtTaskItem2" Margin="5,0"  Text="binding Task Item2"/>
            </StackPanel>
        </Button.Content>
    </Button>

我想要的是这样的:

但是当我运行这个简单的测试程序时,它给了我一个错误信息:

Other information: "set the property" System.Windows.Controls.Viewbox.Child "when the exception is thrown." That number is "81", "41 line position".

如果我删除第二个按钮中使用的第二个静态资源,效果很好! 为什么我不能重用静态资源?! 感谢您的任何提示!

视觉元素只能有一个父元素。通过引用它两次,您可以将它添加到多个父项。在资源上设置 x:Shared="false" 以使其克隆。

一个元素一次只能出现在一个可视化树中。您的路径现在出现在两个按钮的可视化树中。

使用 x:Shared="false" 或仅使用仅更改 Key 的资源再创建一个资源。

用这个 Path 创建一个 UserControl,或者用 Path 创建一个 UserControl