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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:07:51+00:00 2026-06-02T15:07:51+00:00

<UserControl x:Class=JIMS.View.Settings.Settings xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Name=SettingsWindow> <Border Style={StaticResource WindowBorderStyle} Height=100> <StackPanel Orientation=Vertical> <my:TitleBar Title=settings/> <StackPanel

  • 0
<UserControl x:Class="JIMS.View.Settings.Settings"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Name="SettingsWindow">       
    <Border Style="{StaticResource WindowBorderStyle}" Height="100">    
    <StackPanel Orientation="Vertical">
        <my:TitleBar Title="settings"/>
        <StackPanel Orientation="Horizontal">
            <StackPanel Orientation="Horizontal">
                <StackPanel Orientation="Vertical" Margin="10,0,0,0">
                    <Label>Theme :</Label>                        
                </StackPanel>
                <StackPanel Orientation="Vertical" Width="200" Margin="0,0,10,0">                        
                    <ComboBox Name="cmbTheme" ItemsSource="{Binding Path=Themes}" ></ComboBox>                        
                </StackPanel>
            </StackPanel>
        </StackPanel>
    </StackPanel>        
</Border>
</UserControl>

This is my UserControl and i have not set its Width and Height properties.
But in some codebehind i want to get the Height and width of this UserControl and i am not able to get them.

double width=uctrl.Width;

It gives me NaN while

double width=ctrl.ActualWidth;

giving me 0

The code where i need width and height

private void OpenChild(UserControl ctrl)
{
    bool alreadyExist = false;
    ctrl.Uid = ctrl.Name;
    foreach (UIElement child in JIMSCanvas.Children)
    {
        if (child.Uid == ctrl.Uid)
        {
            alreadyExist = true;
            Canvas.SetZIndex(child, GetMaxZIndex);
        }
    }
    if (!alreadyExist)
    {
        JIMSCanvas.Children.Add(ctrl);
            JIMSCanvas.InvalidateMeasure();
        double top = (JIMSCanvas.ActualHeight - ctrl.Height) / 2;
        double left = (JIMSCanvas.ActualWidth - ctrl.Width) / 2;
        Canvas.SetLeft(ctrl, left);
        Canvas.SetTop(ctrl, top);
    }
}
  • 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-02T15:07:52+00:00Added an answer on June 2, 2026 at 3:07 pm

    I solved the Issue with this code…

    private void OpenChild(UserControl ctrl)
    {
        bool alreadyExist = false;
        ctrl.Uid = ctrl.Name;
        foreach (UIElement child in JIMSCanvas.Children)
        {
            if (child.Uid == ctrl.Uid)
            {
                alreadyExist = true;
                Canvas.SetZIndex(child, GetMaxZIndex);
            }
        }
        if (!alreadyExist)
        {
            JIMSCanvas.Children.Add(ctrl);
            JIMSCanvas.UpdateLayout();
            double top = (JIMSCanvas.ActualHeight - ctrl.ActualHeight) / 2;
            double left = (JIMSCanvas.ActualWidth - ctrl.ActualWidth) / 2;
            Canvas.SetLeft(ctrl, left);
            Canvas.SetTop(ctrl, top);                               
        }
    }
    

    I have used JIMSCanvas.UpdateLayout();

    Thank all for helping and especially @NestorArturo

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

Sidebar

Related Questions

See the following XAML: <UserControl xmlns:sdk=http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk x:Class=SilverlightApplication1.MainPage xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 mc:Ignorable=d d:DesignHeight=300 d:DesignWidth=400
In my view, I have: <UserControl x:Class ... MouseDown=UserControl_MouseDown> <Viewport3D Name=Viewport Grid.Column=0> ... </Viewport3D
I have created a UserControl name TitleBar, which is placed in every view. The
The UserControl class inherits from TemplateControl which implements INamingContainer. Since this is only a
I've got a usercontrol which inherits from the UserControl class. There are a bunch
Lets say i have this usercontrol public class test : UserControl { public int
say I have this control: public partial class bloc999 : UserControl { bloc999Data mainBlock
All, I have a simple class. public class Container : UserControl { public bool
If I create a class that extends UserControl and want to set a default
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static

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.