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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:40:21+00:00 2026-06-13T08:40:21+00:00

I have a WPF app that I’m testing which loads a XML and visualizes

  • 0

I have a WPF app that I’m testing which loads a XML and visualizes it in a usercontrol. Now the issue I’m having is that every time I load my user control the HorizontalAlignment is okay, but the VerticalAlignment doesn’t adept to the height size of the usercontrol.

Anyone has an idea how to solve this?

MainWindow.xaml

        <Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:UserControls="clr-namespace:RackBuildingTesT.UserControls" x:Class="RackBuildingTesT.MainWindow"
    Title="MainWindow" Height="578" Width="758" SizeChanged="Window_SizeChanged_1">
<Grid>
        <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1">
                <Grid>
                    <Label Content="Welke rack laden" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <ComboBox x:Name="RackChooser" HorizontalAlignment="Left" Margin="100,0,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="RackChooser_SelectionChanged"/>
                </Grid>
            </Border>
        <Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="1">
            <Grid x:Name="RackGrid" Margin="0,0,0,0">
            </Grid>
        </Border>
        </DockPanel>
    </Grid>

MainWindow.xaml.cs

        public MainWindow()
    {
        InitializeComponent();
        LoadRackCombo();
    }
    private void LoadRackCombo()
    {
        var files = Directory.GetFiles(Properties.Settings.Default.FilePathXMLRack);
        foreach (var item in files)
        {
            RackChooser.Items.Add(item);
        }
    }

    private void RackChooser_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        this.RackGrid.Children.Clear();
        this.Cursor = Cursors.Wait;
        if (RackChooser.SelectedIndex == -1)
            MessageBox.Show("Select a rack");
        else
        {
            string rackFile = Convert.ToString(RackChooser.Items[RackChooser.SelectedIndex]);
            UserControls.RackBuilder r = new UserControls.RackBuilder();
            RackGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            RackGrid.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            r.Width = RackGrid.Width;
            r.Height = RackGrid.Height;
            var _r = TRack.CreateFromXMLFile(rackFile, null);
            r.set_Rack(_r);
            RackGrid.Children.Add(r);
        }
        this.Cursor = Cursors.Arrow;
    }

    private void Window_SizeChanged_1(object sender, SizeChangedEventArgs e)
    {
        RackGrid.Width = this.Width;
        RackGrid.Height = this.Height;
    }

RackBuilder.xaml.cs (xaml page is standard WPF usercontrol)

        public RackBuilder()
    {
        InitializeComponent();
    }

    public TRack fRack { get; set; }

    public void set_Rack(TRack value)
    {
        this.fRack = value;
        this.InvalidateVisual();
    }

    protected override void OnRender(DrawingContext drawingContext)
    {
        if (this.fRack != null)
        {
            var xScale = this.Width / this.fRack.Size.Width;
            var yScale = this.Height / this.fRack.Size.Height;
            var smallest = 0.0;

            if (xScale < yScale)
                smallest = xScale;
            else
                smallest = yScale;

            foreach (var hole in this.fRack.HolePositions)
            {
                drawingContext.DrawEllipse(Brushes.Aquamarine, null, new Point(hole.Position.X * xScale, hole.Position.Y * yScale),
                                           hole.Diameter * smallest * 0.5, hole.Diameter * smallest * 0.5);
            }
        }
    }

Result

Result of App

  • 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-13T08:40:22+00:00Added an answer on June 13, 2026 at 8:40 am

    I fixed it with putting the MainWindow SizeToContent to WidthAndHeight.

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

Sidebar

Related Questions

I have a WPF app that I'm testing on a Samsung XE700T1A tablet. I
I have a C# WPF app that every time the user opens a new
I have a WPF app that uploads XML data to a web service asynchronously.
I'm having an issue using a new WPF app that is trying to display
I have a WPF app that binds a DataGrid to an XML document using
I have a WPF App that implements a ListView. I would like to show
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have a wpf app that needs to communicate(exchange data) with a custom designed
We have a WPF app that allows our users to download encrypted content and
I have a WPF app, my purpose is that the app can be automatically

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.