如何在XAML中冻结从Freezable派生的WPF对象?
WPF中的许多类型都源自如何在XAML中冻结从Freezable派生的WPF对象?,wpf,performance,xaml,freezable,Wpf,Performance,Xaml,Freezable,WPF中的许多类型都源自Freezable。它为可变POCO对象提供了不变性,并允许在某些情况下提高性能 所以我的问题是,如何在XAML标记中冻结对象 (请注意,我也发布了一个声明)。将此添加到您的xaml命名空间声明中: xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibil
Freezable
。它为可变POCO对象提供了不变性,并允许在某些情况下提高性能
所以我的问题是,如何在XAML标记中冻结对象
(请注意,我也发布了一个声明)。将此添加到您的xaml命名空间声明中:
xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="po"
然后,在可自由化的对象中,包含此属性
po:Freeze="True"
要冻结标记中声明的
Freezable
对象,可以使用XML名称空间http://schemas.microsoft.com/winfx/2006/xaml/presentation/options
在下面的示例中,SolidColorBrush
被声明为页面资源并被冻结。然后使用它设置按钮的背景
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="po">
<Page.Resources>
<!-- This brush is frozen -->
<SolidColorBrush x:Key="MyBrush" po:Freeze="True" Color="Red" />
</Page.Resources>
<!-- Use the frozen brush -->
<Button Background="{StaticResource MyBrush}">Click Me</Button>
</Page>
点击我
来源:mc名称空间从何而来?哦,我想我错过了。现在已修复。最后一个属性不应该是
mc:Ignorable=“po”
?