运行 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>
Run Code Online (Sandbox Code Playgroud)
如何重用Viewbox资源?
将x:Shared它的属性设置为false:
<Viewbox x:Key="MyBox" x:Shared="False" Stretch="Uniform">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1213 次 |
| 最近记录: |