2009-04-28 11 views

risposta

38

di congelare un oggetto Freezable dichiarato nel markup, si utilizza l'attributo Freeze definito nello spazio dei nomi XML http://schemas.microsoft.com/winfx/2006/xaml/presentation/options.

Nell'esempio seguente, un SolidColorBrush viene dichiarato come risorsa di pagina e bloccato. Viene quindi utilizzato per impostare lo sfondo di un pulsante.

<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> 

Fonte: Freezable Objects Overview

+2

L'ultimo attributo non dovrebbe essere 'mc: Ignorable =" po "'? – CodeNaked

+0

@CodeNaked, credo che tu abbia ragione. Modificato. –

9

Aggiungere questo ai vostri dichiarazioni di namespace XAML:

xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="po" 

poi, nei vostri oggetti congelabili, includere questo attributo

po:Freeze="True" 
+0

Da dove viene lo spazio dei nomi 'mc' viene? –

+0

Oh, penso di averlo perso. Risolto adesso – Botz3000