Windows Presentation Foundation

Hello, WPF

WPF from Scratch
Navigation Applications
Content Model
Layout
Controls
Data Binding
Dependency Properties
Resources
Styles and Control Templates
Graphics
Application Deployment
Where Are We?

Layout

Introduction
Layout Basics
DockPanel
StackPanel
Grid
Canvas
Viewbox
Text Layout
Common Layout Properties
When Content Doesn't Fit
Custom Layout
Where Are We?

Controls

Introduction
What Are Controls?
Handling Input
Built-In Controls
Where Are We?

Data Binding

Introduction
Without Data Binding
Data Binding
Binding to List Data
Data Sources
Master-Detail Binding
Where Are We?

Styles and Control Templates

Introduction
Without Styles
Inline Styles
Named Styles
Element-Typed Styles
Data Templates and Styles
Triggers
Control Templates
Where Are We?

Resources

Introduction
Creating and Using Resources
Resources and Styles
Binary Resources
Global Applications
Where Are We?

Graphics

Introduction
Graphics Fundamentals
Shapes
Brushes and Pens
Transformations
Visual-Layer Programming
Video and 3-D
Where Are We?

Animation

Animation Fundamentals
Timelines
Storyboards
Key Frame Animations
Creating Animations Procedurally
Where Are We?

Custom Controls

Introduction
Custom Control Basics
Choosing a Base Class
Custom Functionality
Templates
Default Visuals
Where Are We?

ClickOnce Deployment

A Brief History of Windows Deployment
ClickOnce: Local Install
The Pieces of ClickOnce
Publish Properties
Deploying Updates
ClickOnce: Express Applications
Choosing Local Install versus Express
Signing ClickOnce Applications
Programming for ClickOnce
Security Considerations
Where Are We?

When Content Doesn't Fit

When Content Doesn't Fit

Sometimes, WPF will not be able to honor your requests because you have asked the impossible. Example 2-34 creates a StackPanel with a Height of 100, which contains a Button with a Height of 195.

Example 2-34. Asking the impossible
<StackPanel Height="100" Background="Yellow" Orientation="Horizontal">
    <Button>Foo</Button>
    <Button Height="30">Bar</Button>
    <Button Height="195">Spong</Button>

</StackPanel>

Clearly that last button is too big to fitit is taller than its containing panel. Figure 2-42 shows how WPF deals with this.

Figure 2-42. Truncation when content is too large


The StackPanel has dealt with the anomaly by truncating the element that was too large. When confronted with contradictory hardcoded sizes like these, most panels take a similar approach and will crop content where it simply cannot fit.

There is some variation in the way that panels handle overflow in situations where sizes are not hardcoded but there is still too much content to fit. Example 2-35 puts the three copies of a TextBlock and its content into a StackPanel, a DockPanel, and a Grid cell.

Example 2-35. Handling overflow
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <StackPanel Height="100" Background="Yellow" Orientation="Horizontal">
        <TextBlock TextWrap="Wrap" FontSize="20">
            This is some text that is too long to fit.
        </TextBlock>
    </StackPanel>

    <DockPanel Grid.Row="1" Height="100" Background="Yellow" LastChildFill="False">

        <TextBlock TextWrap="Wrap" FontSize="20">
            This is some text that is too long to fit.
        </TextBlock>
    </DockPanel>

    <TextBlock Grid.Row="2" TextWrap="Wrap" FontSize="20">
        This is some text that is too long to fit.
    </TextBlock>

</Grid>

Figure 2-43 shows what happens when the available space is too narrow to hold the TextBlock at its natural length.

Figure 2-43. Overflow handling


The StackPanel has simply truncated the TextBlock. The DockPanel and Grid have been slightly more intelligent. They have exploited the fact that the TextBlock had wrapping enabled and were able to flow the text into the narrow space available.


©2008 FAQ - WPF Labs - Discuss - Terms of Use - Privacy Policy - About WPF
- Interview Questions - Sharepoint Articles - Interview Questions Resource Library - All about LINQ - MS Knowledgebase Articles - Electronics and Hardware discussions