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

  • Home
  • SEARCH
  • 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 9266341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:17:44+00:00 2026-06-18T14:17:44+00:00

if I have this XAML: <Grid xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <StackPanel Orientation=Horizontal> <Grid Background=Gray Margin=5 Height=200

  • 0

if I have this XAML:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<StackPanel Orientation="Horizontal">
    <Grid Background="Gray" Margin="5"
        Height="200" Width="200">
        <Rectangle Fill="Blue" />
    </Grid>
    <Canvas Background="Gray" Margin="5"
        Height="200" Width="200">
        <Rectangle Fill="Blue" />
    </Canvas>
    <StackPanel Background="Gray" Margin="5"
        Height="200" Width="200">
        <Rectangle Fill="Blue" />
    </StackPanel>
</StackPanel>

Only the Grid is filled by the blue rectangle, But I would like the Canvas to operate the same way and be filled with the blue rectangle?

I am up for making a custom canvas, but not sure how to go about it.

Any suggestions?

  • 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-06-18T14:17:45+00:00Added an answer on June 18, 2026 at 2:17 pm

    You could try something like this:

    <Canvas x:Name="myCanvas" Background="Gray" Margin="5"
        Height="200" Width="200">
        <Rectangle Fill="Blue"
                   Height="{Binding ElementName=myCanvas, Path=ActualHeight}"
                   Width="{Binding ElementName=myCanvas, Path=ActualWidth}" />
    </Canvas>
    

    This will tell the rectangle to take it’s dimensions from the actual dimensions of the named element.

    The reason only the Grid is filled is because it’s the only one that tells it’s children what size to be. The StackPanel takes it’s size from the combined size of all it’s children and the Canvas is the size you tell it to be but doesn’t resize any child elements.

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

Sidebar

Related Questions

I have this XAML: <Window x:Class=WpfBindToCodeBehind.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Window1 Height=300 Width=300 Loaded=Window_Loaded> <StackPanel Orientation=Vertical>
I have this: <Window x:Class=ScrollTest.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=450 Width=525> <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility=Visible ScrollViewer.VerticalScrollBarVisibility=Visible> <Grid>
i have this DataTemplate: <ResourceDictionary xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:Model=clr-namespace:Effectus.Model xmlns:Controls=clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit > <DataTemplate DataType={x:Type Model:ToDoAction}> <Grid>
I have this simplified version of my app in XAML: <UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
I have this context menu resource: <ResourceDictionary xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <ContextMenu x:Key=FooContextMenu> <ContextMenu.CommandBindings> <CommandBinding Command=Help
Hi i have a xaml code like this <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml x:Class=test.Window1 x:Name=Window Title=Window1
I have this xaml: <Window x:Class=WPFExample.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WPFExample xmlns:telerik=http://schemas.telerik.com/2008/xaml/presentation Title=MainWindow Height=350 Width=525 xmlns:sys=clr-namespace:System;assembly=mscorlib>
I have page like this ... <Page x:Class=WPFTestRig.Page1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Page1> <Grid> <StackPanel> <ComboBox
I have a WPF window with this xaml: <Window x:Class=WpfApplication2.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350
i have this code: <Window x:Class=WpfApplication8.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Grid> <ScrollViewer Background=#FFADB9CD

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.