重复使用Viewbox资源

4

正在运行 Visual Studio 2017,并且目标为 .NET 4.6.1。考虑以下 XAML。在 XAML 编辑器中,您可以看到两个圆,但在运行应用程序时,只会显示第二个圆。

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Window.Resources>
        <Viewbox x:Key="MyBox" Stretch="Uniform">
            <Ellipse Width="4" Height="4" Fill="Red"/>
        </Viewbox>
    </Window.Resources>
    <StackPanel>
        <ContentPresenter Width="100" Content="{StaticResource MyBox}"/>
        <ContentPresenter Width="100" Content="{StaticResource MyBox}"/>
    </StackPanel>
</Window>

您如何重复使用一个 Viewbox 资源?
1个回答

7

将其x:Shared属性设置为false:

<Viewbox x:Key="MyBox" x:Shared="False" Stretch="Uniform">

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接