:: Home

  login:         
  passwords:  

WPF FAQs

WPF General Questions
Concepts Element Tree
Concepts Dependency Property
Concepts Attached Property
Concepts Routed Events
Concepts Resources.
Concepts Animation
Concepts Freezable Object
Concepts Input and Commands.
Concepts Layouts
XAML Inline Styles and Templates
XAML XML Namespaces
XAML Code Behind
XAML Custom Class
XAML Type Converters
Content Model ItemControl
Content Model HeaderedItemsControl
Content Model HeaderedContentControl
Content Model Content Control
Content Model Decorator Content Model
Content Model Panel Content Model
Documents Serialization and Storage
Documents Annotations
Documents Flow Content
Documents Printing
Graphics and Multimedia Rendering Graphics
Graphics and Multimedia Animation and Timing
Graphics and Multimedia 2D Graphics
Graphics and Multimedia 3D Graphics
Graphics and Multimedia Visual Layer
Control Customization Adorners
Control Customization Stylable controls
Control Customization ControlTemplates
Data Data Binding
Data DragandDrop
Data Serialization
Globalization and Localization Attributes
Globalization and Localization Comments
Globalization and Localization Globalization Struc
Application and Deployment ClickOnce
Application and Deployment Frame
Application and Deployment Page
Application and Deployment Navigation
Application and Deployment Setup
Application and Deployment Window
Interoperability Message Loops Between
Interoperability Win32 in WPF
Interoperability WPF in Win32
Interoperability Windows Forms and WPF
Security Trusted Security
Security Partial Trust Security
Tools Microsoft Expression Blend
Tools ZAM3D
Tools XAMLPAD
Controls ToolTip
Controls TextBlock
Controls TabControl
Controls ProgressBar
Controls PrintDialog
Controls Popup
Controls TextBox
Controls Canvas
Controls ComboBox
Controls ListBox
Controls StatusBar
Controls ToolBar
Controls Context Menu
Controls Expander
Controls DocumentViewer
Controls FlowDocumentReader
Controls GroupBox
Controls GridSplitter
Controls Image
Controls Menu
Controls ScrollBar
Controls Slider
Controls RichTextBox
Controls Border
Controls Buttons

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

Winforms Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Concepts Freezable Object Interview Questions & FAQs

Questions and answers for Concepts Freezable Object.

8. Concepts Freezable Object

    8.1 What is a Freezable?
    8.2 How can I determine whether a Freezable Is Frozen?
    8.3 How can I obtain a writable copy of a Read-Only Freezable?

8.1 What is a Freezable?

The following example shows an application definition file. The application definition file defines a resource section (a value for the Resources property). Resources defined at the application level can be accessed by all other pages that are part of the application. In this case, the resource is a declared style. Because a complete style that includes a control template can be lengthy, this example omits the control template that is defined within the "ContentTemplate" property setter of the style.

[XAML]

<Application.Resources>

<Style TargetType="Button" x:Key="GelButton" >

<Setter Property="Margin" Value="1,2,1,2"/>

<Setter Property="HorizontalAlignment" Value="Left"/>

<Setter Property="Template">

<Setter.Value>

     ...

</Setter.Value>

</Setter>

</Style>

</Application.Resources>

The following example shows an XAML page that references the application level resource that the previous example defined. The resource is referenced by using a StaticResource Markup Extension that specifies the unique resource key for the requested resource. No resource with the key of "GelButton" is found in the current page, so the resource lookup scope for the requested resource continues beyond the current page and into the defined application level resources.

[XAML]

<StackPanel

Name="root"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1" />

<Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 2" />

</StackPanel>


8.2 How can I determine whether a Freezable Is Frozen?

This example shows how to determine whether a Freezable object is frozen. If you try to modify a frozen Freezable object, it throws an 'Invalid Operation' Exception. To avoid throwing this exception, use the "IsFrozen" property of the Freezable object to determine whether it is frozen.

[C#]

Button myButton = new Button();

SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);

if (myBrush.CanFreeze)

{

// Makes the brush unmodifiable.

myBrush.Freeze();

}

myButton.Background = myBrush;

if (myBrush.IsFrozen) // Evaluates to true.

{

// If the brush is frozen, create a clone and

// modify the clone.

SolidColorBrush myBrushClone = myBrush.Clone();

myBrushClone.Color = Colors.Red;

myButton.Background = myBrushClone;

}

else

{

// If the brush is not frozen,

// it can be modified directly.

myBrush.Color = Colors.Red;

 

8.3 How can I obtain a writable copy of a Read-Only Freezable?

This example shows how to use the Clone method to create a writable copy of a read-only Freezable. After a Freezable object is marked as read-only ("frozen"), you cannot modify it. However, you can use the 'Clone' method to create a modifiable clone of the frozen object.

The following example creates a modifiable clone of a frozen 'SolidColorBrush' object.

[C#]
Button myButton = new Button();
SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);
 
[C#]
// Freezing a Freezable before it provides
// performance improvements if you don't
// intend on modifying it.
if (myBrush.CanFreeze)
{
// Makes the brush unmodifiable.
myBrush.Freeze();
}

myButton.Background = myBrush;

// If you need to modify a frozen brush,
// the Clone method can be used to
// create a modifiable copy.
SolidColorBrush myBrushClone = myBrush.Clone();

// Changing myBrushClone does not change
// the color of myButton, because its
// background is still set by myBrush.
myBrushClone.Color = Colors.Red;

// Replacing myBrush with myBrushClone
// makes the button change to red.
myButton.Background = myBrushClone;

bottom user control
::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd