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 6721453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:19:55+00:00 2026-05-26T09:19:55+00:00

In my earlier example of Input Box, I have a window variable. I created

  • 0

In my earlier example of Input Box, I have a window variable. I created some controls(Textbox, Label, Buttons). Parent of these controls is canvas. Parent of canvas is a ViewBox (because ViewBox can only contain one child) and parent of ViewBox is the window.
So hierarchy is like Window->Viewbox->Canvas-> Controls. All these control creation and parenting is done dynamically.

        winInputDialog = new Window();
        lblPrompt = new Label();
        btnOK = new Button();
        btnCancel = new Button();
        txtInput = new TextBox();
        cvContainer = new Canvas();
        VB = new Viewbox();

        // 
        // lblPrompt
        // 
        lblPrompt.Background = new SolidColorBrush(SystemColors.ControlColor);
        lblPrompt.FontFamily = new FontFamily("Microsoft Sans Serif");
        lblPrompt.FontSize = 12;
        lblPrompt.Background = new SolidColorBrush(Colors.Transparent);
        lblPrompt.FontStyle = FontStyles.Normal;
        lblPrompt.Margin = new Thickness(8, 9, 0, 0);
        lblPrompt.Name = "lblPrompt";
        lblPrompt.Width = 302;
        lblPrompt.Height = 82;
        lblPrompt.TabIndex = 3;
        // 
        // btnOK
        // 
        btnOK.Margin = new Thickness(322, 8, 0, 0);
        btnOK.Name = "btnOK";
        btnOK.Width = 64;
        btnOK.Height = 24;
        btnOK.TabIndex = 1;
        btnOK.Content = "OK";
        btnOK.Click += new RoutedEventHandler(btnOK_Click);
        // 
        // btnCancel
        //          
        btnCancel.Margin = new Thickness(322, 40, 0, 0);
        btnCancel.Name = "btnCancel";
        btnCancel.Width = 64;
        btnCancel.Height = 24;
        btnCancel.TabIndex = 2;
        btnCancel.Content = "Cancel";
        btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
        // 
        // txtInput
        // 
        txtInput.Margin = new Thickness(8, 70, 0, 0);
        txtInput.Name = "txtInput";
        txtInput.Width = 379;
        txtInput.Height = 25;
        txtInput.TabIndex = 0;
        //
        //Canvas
        //

        double width = System.Windows.SystemParameters.PrimaryScreenWidth / 3, height = System.Windows.SystemParameters.PrimaryScreenHeight / 4;

        cvContainer.Height = height;
        cvContainer.Width = width;

        cvContainer.Children.Add(txtInput);
        cvContainer.Children.Add(btnCancel);
        cvContainer.Children.Add(btnOK);
        cvContainer.Children.Add(lblPrompt);
        cvContainer.ClipToBounds = true;
        //
        //ViewBox
        //            
        VB.Stretch = Stretch.Fill;
        VB.Child = cvContainer;
        // 
        // InputBoxDialog
        //
        winInputDialog.Width = width;
        winInputDialog.Height = height;            
        winInputDialog.Content = VB;
        winInputDialog.Icon = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(System.IO.Directory.GetCurrentDirectory() + @"\drop-box-icon.png"));
        winInputDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //winInputDialog.WindowStyle = WindowStyle.SingleBorderWindow;
        winInputDialog.ResizeMode = ResizeMode.CanResizeWithGrip;
        winInputDialog.Name = "InputBoxDialog";

I have set the width and height property of canvas equal to window. But why my screen look like this:

screen

Why is there space between controls and window borders even though they are in viewbox. I even tried Cliptobounds but still the same.

If i set Viewbox height and width it does not stretch and behave unlike a Viewbox.

i want to set this screen dynamically. How?

Sample Project is at http://122.160.24.172/download/customer_data/InputBox_New.rar.

  • 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-26T09:19:56+00:00Added an answer on May 26, 2026 at 9:19 am

    If you want your window to have a dynamic layout, why won’t you use a dynamic container unlike Canvas which is static?

    You could use a Grid like this –

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.8*"/>
            <ColumnDefinition Width ="0.2*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock Text="Hello"/>
        <Button Grid.Column="1" Content="Ok"/>
        <Button Grid.Row="1" Grid.Column="1" Content="Cancel"/>
        <TextBox Grid.Row="2" Grid.ColumnSpan="2" Text="Hello"/>
    </Grid>
    

    This way your window will layout itself when its size is changed.
    You can still adjust the button size and margin if you’d like.

    Don’t use a Canvas unless you really need support for exact pixel coordination positioning layout.

    Also: Why are you layouting your window programatically and not in XAML?

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

Sidebar

Related Questions

For example, I have created a slew of 'test-my-service' Objects in my Spring config
Earlier I asked why this is considered bad: class Example { public: Example(void); ~Example(void);
Earlier today a question was asked regarding input validation strategies in web apps .
I saw in an earlier post here on stackoverflow a example on many to
For example I have 2 tables: topics and comments. topic has_many comments. comment belongs_to
I'm developing Javascript for a website called www.example.com and Chrome keeps caching earlier versions
Can I define that application was installed earlier? For example I can check whether
I posted a similar question earlier and received some good suggestions. After further investigation,
I have a map<char*, int> labels; thats exhibiting some behavior that I can't wrap
I asked this question earlier: mod_rewrite: match only if no previous rules have matched?

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.