WPF form not same when run

WPF form not same when run

manhgt214
Enthusiast Enthusiast
507 Views
4 Replies
Message 1 of 5

WPF form not same when run

manhgt214
Enthusiast
Enthusiast

why my form not show same when run in revit.

<Window x:Class="Basic1.WPF1"
            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" 
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:local="clr-namespace:Basic1"
            mc:Ignorable="d" 
            Title="WPF RevitAPI"
            WindowStartupLocation="CenterScreen"
            ResizeMode="NoResize"
            MaxHeight="250"
            MaxWidth="400"
            Height="250" 
            Width="400">

    <Grid>

        <Button 
            Content="OK"
            VerticalAlignment="Bottom"
            HorizontalAlignment="Right"
            Margin="0,0,20,20"
            Height="25"
            Width="70" Click="Button_Click_1"/>

        <Button 
            Content="Cancel"
            VerticalAlignment="Bottom"
            HorizontalAlignment="Right"
            Margin="0,0,150,20"
            Height="25"
            Width="70" Click="Button_Click"/>
        <GroupBox
            VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"
            Header="Get List Family"
            Margin="15,10,15,70"
            Height="150"
            Width="370" 
            BorderBrush="Red"
            BorderThickness="2,2,2,2"/>

    </Grid>

</Window>

 

manhgt214_2-1713413311092.png

 

0 Likes
Accepted solutions (1)
508 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

I cannot say what exact setting might be causing this. However, it is quite common for a WPF form to appear differently in runtime than in the designer. Here is a discussion explaining some possible causes of why a WPF window layout looks different from VS designer when running:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

Niko_Davydov
Advocate
Advocate

Hi @manhgt214 ,

you can try to change WindowStyle property. Window.WindowStyle Property (System.Windows) | Microsoft Learn

As Example

<Window x:Class="Basic1.WPF1"
            WindowStartupLocation="CenterScreen"
            WindowStyle="None"
            ResizeMode="NoResize"
            MaxHeight="250"
            MaxWidth="400"
            Height="250" 
            Width="400">
<--... you code-->

 
Best regards,

Nikolai Davydov

Message 4 of 5

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @manhgt214 

 

    While designing the WPF form make sure you have a complete understanding of Grids.Because Grids play a major role in WPF Form design. I have changed your code a little bit so it became scalable. Try to understand the code which I have written and implement it.

 

Updated XAML Code

<Window x:Class="Basic1.WPF1"
            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" 
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:local="clr-namespace:Basic1"
            mc:Ignorable="d" 
            Title="WPF RevitAPI"
            WindowStartupLocation="CenterScreen"
            ResizeMode="NoResize"
            MaxHeight="250"
            MaxWidth="400"
            Height="250" 
            Width="400">

    <!--Make 10 Pixel Offset-->
    <Grid Margin="10">

        <!--Form Layout-->
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="70"/>
            <ColumnDefinition Width="70"/>
        </Grid.ColumnDefinitions>

        <GroupBox VerticalAlignment="Stretch"
            HorizontalAlignment="Stretch"
            Header="Get List Family"
            BorderBrush="Red"
            BorderThickness="2,2,2,2"
            Grid.ColumnSpan="3"/>

        <Button Content="OK" Grid.Row="1" Grid.Column="2" Margin="3" Click="Button_Click"/>
        <Button Content="Cancel" Grid.Row="1" Grid.Column="1" Margin="3" Click="Button_Click"/>

    </Grid>
</Window>

Output Image

Mohamed_Arshad_0-1713439154856.png

 

Hope this will Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 5 of 5

manhgt214
Enthusiast
Enthusiast

Thank you so much!