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
L'ultimo attributo non dovrebbe essere 'mc: Ignorable =" po "'? – CodeNaked
@CodeNaked, credo che tu abbia ragione. Modificato. –