TBC Macros and Extensions

 View Only
Expand all | Collapse all

Why WPF content is being messed at the Runtime?

  • 1.  Why WPF content is being messed at the Runtime?

    Posted 04-17-2023 14:47
    Edited by Morteza Kiani 04-17-2023 14:57

    Hello Trimble Community,

    Could somebody please explain why my wpf formatting is being messed up at runtime? Left below is the what I expect to see and Right below is what I see after running the wpf. 

    I tried to override the formatting on OnLoad() which is not the great way but it still does not do what I need.

    # Load Event of the WPF Class
        def OnLoad(self, cmd, buttons, event):
            self.mypannel.Width=1000
            self.mypannel.Height=400


    and here is the stack panel that I'm dealing with. BTW, is there anyway to bring in Grid or Canvas or Is it possible to have access the window element like standard wpf? Any help will be appreciated!

    <StackPanel x:Name="mypannel" Background="BlueViolet" Width="700" Height="283"
           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" xmlns:Wpf="clr-namespace:Trimble.Vce.UI.Controls.Wpf;assembly=Trimble.Vce.UI.Controls" mc:Ignorable="d"  HorizontalAlignment="Stretch"  Margin="4" >
    
        <TextBlock Text="Select the Utility Network:" FontSize="13" FontWeight="Bold" Margin="5 0 0 2"/>
        <Wpf:ComboBoxEntityPicker x:Name="utilitynetworkslist" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
        <Button x:Name="BrowsetoXML" Content="Browse to Source XML" Click="BrowsetoXML_Click"/>
        <TextBlock x:Name="Tb2" Text="Total Number of the Element:"/>
        <TextBlock Text="Nodes:" Margin="0,4"/>
        <ListBox x:Name="LB1" VerticalAlignment="Center" VerticalContentAlignment="Center" Background="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" Height="158"/>
    
    
    
    </StackPanel> 







    ------------------------------
    Morteza Kiani
    ------------------------------



  • 2.  RE: Why WPF content is being messed at the Runtime?

    Posted 04-17-2023 19:16

    Try d:DesignWidth and d:DesignHeight. Don't ask me for an explanation but that is what the sample macros use.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 3.  RE: Why WPF content is being messed at the Runtime?

    Posted 04-18-2023 19:45

    Thanks Ronny! I won't ask for it lol!




    ------------------------------
    Morteza Kiani
    ------------------------------



  • 4.  RE: Why WPF content is being messed at the Runtime?

    Posted 04-18-2023 09:46
    It looks like you are setting the VerticalAlignment or VerticalContentAlignment  to "Center", either in your __init__ or OnLoad methods. If that is not the case, try setting the VerticalContentAlignment to "Top" in your xaml and see if that makes a difference.

    Using the "d:" just tells the designer (Visual Studio) to use the value.  Since there is mc:Ignorable="d", it will be ignored at runtime.  Personally I use d:Width and d:Height on all my xaml files.  I have found that different versions of Visual Studio make different assumptions on the height and width and this was the only way to make it consistent across the versions.

    TBC expects the first / outer control to be a StackPanel.  However you can make the first child of the StackPanel a Canvas or Grid control. I make extensive use of the Grid in our commands. I have used the Canvas in a couple of commands but have less experience using it.

    Peter





  • 5.  RE: Why WPF content is being messed at the Runtime?

    Posted 04-18-2023 19:53

    "d:" Worked nicely. I'm used to start from <window>  element and looks like they made it limited to start from StackPanel so it's not a complete wpf deal. luckily it works for me  on VS 2019 so far. 

    Thanks!




    ------------------------------
    Morteza Kiani
    ------------------------------