2009-04-28 52 views

回答

38

要凍結在標記聲明的Freezable對象,您使用Freeze屬性在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> 

來源:Freezable Objects Overview

9

添加到您的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" 
+0

在什麼地方 'MC' 命名空間從何而來? – 2009-08-25 09:11:13

+0

哦,我想我錯過了。現在修復它。 – Botz3000 2009-08-25 09:16:13