Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 249273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:24:49+00:00 2026-05-11T21:24:49+00:00

I was wondering if anyone knew how to duplicate the 9-slice functionality of Flex/Flash

  • 0

I was wondering if anyone knew how to duplicate the 9-slice functionality of Flex/Flash in WPF and VB.Net. I have used 9-slice scaling many times in Flex and it would be a great asset in WPF. I would like to be able to have an image as my background of a Canvas and have it stretch without ruining the rounded corners. Please, does anyone know how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:24:49+00:00Added an answer on May 11, 2026 at 9:24 pm

    I’m not aware of any built-in functionality that can do this, but you could write a custom control to do so.

    The salient part of such a control would be a 9 part grid in which 4 parts were of fixed size (the corners), two parts had fixed heights and variable widths (center top and center bottom), two parts had fixed widths and variable heights (left center and right center), and the final part had variable height and width (the middle). Stretching in only one direction (e.g. making a button that only grows horizontally) is as simply as limiting the middle portion’s height.

    In XAML, that would be:

    <Grid>
        <Grid.ColumnDefinitions>
            <!-- 20 is the amount of pixel on your image corner -->
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>
    </Grid>
    

    Then you’d add objects to paint the images on to (I’ll use Rectangles), as well as an object to put content into (ContentPresenter):

    <Rectangle Grid.Row="0" Grid.Column="0" x:Name="TopLeft"/>
    <Rectangle Grid.Row="0" Grid.Column="1" x:Name="TopCenter"/>
    <Rectangle Grid.Row="0" Grid.Column="2" x:Name="TopRight"/>
    
    <Rectangle Grid.Row="1" Grid.Column="0" x:Name="CenterLeft"/>
    <Rectangle Grid.Row="1" Grid.Column="2" x:Name="CenterRight"/>
    
    <Rectangle Grid.Row="2" Grid.Column="0" x:Name="BottomLeft"/>
    <Rectangle Grid.Row="2" Grid.Column="1" x:Name="BottomCenter"/>
    <Rectangle Grid.Row="2" Grid.Column="2" x:Name="BottomRight"/>
    
    <Grid Grid.Row="1" Grid.Column="1" x:Name="Middle">
      <Rectangle/>
      <ContentPresenter x:Name="MiddleContent"/>
    </Grid>
    

    Each of the Rectangles can be painted using an ImageBrush so that they show the correct portion of your source image:

    <Rectangle>
        <Rectangle.Fill>
            <ImageBrush ImageSource="Image.png" TileMode="None" 
                        <!-- Add the settings necessary to show the correct part of the image --> />
        </Rectangle.Fill>
    </Rectangle>
    

    Wrapping all of that up into a custom control, you could produce a pretty usable 9-slice image control:

    <local:NineSliceImage Image="Source.png" Slice="20,20">
        <TextBox Text="Nine Slice Image TextBox!"/>
    </local:NineSliceImage>
    

    Where Slice is a property of type System.Windows.Size, so that you can use it like the Margin/Padding/etc. properties for setting the position of the slices.

    You’ll also want to set SnapToDisplayPixels to True on all of the Rectangles; otherwise, you’ll see small gaps between the pieces of the image at certain resolutions as WPF tries to interpolate the in-between pixels.

    An alternative, slightly faster way of doing this if you plan to use a lot of these controls is to override OnRender and do it there; I’ve done this in the past for a 3-slice image control, but it’s quite a bit more tricky.

    That should get you most of the way there – if there’s anything I’m missing, leave a comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone knew whether Visual Studio .NET had a parallel build
I was wondering if anyone knew why jQuery doesn't have a simple $().id() method.
I was wondering if anyone knew how to go about creating functionality like there
Was wondering if anyone knew of some third party android development toolkits. I have
I was wondering if anyone knew of any webhosts that let you deploy asp.net
I was wondering if anyone knew what was the format of a ASP.NET SessionID?
I was wondering if anyone knew of an application that would show the flash
Just wondering if anyone knew off the top of their heads if there was
I was wondering if anyone knew of any limitations to using Windows XP as
I was wondering if anyone knew of a macro or keyboard shortcut or anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.