- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
This post relates to this post by @adam.nagy so hopefully he will see and reply directly but:
I am attempting to create a wpf window inside of an Inventor Addin- I know I can do this with a windows form, but I found Adam's post and thought I would give it a try.
Inside of the Addin I added a User Control and placed the following code inside:
<Window x:Class="Power_Pack_For_Inventor_AddIn.SelectFeaturesWindow" 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:Power_Pack_For_Inventor_AddIn" mc:Ignorable="d" ResizeMode="CanResize" Height="354.667" Width="457.333" BorderThickness="2" SizeToContent="WidthAndHeight" Padding="0"> <StackPanel Background="Gray" Margin="0,0,0,0"> <Button x:Name="button" Content="Button" VerticalAlignment="Bottom" Margin="0,0,0,0"/> <Border BorderBrush="OldLace" BorderThickness="10" CornerRadius="10" HorizontalAlignment="Center" VerticalAlignment="Center"> <Image Source="ksp.jpg" Width="200" Height="200" Stretch="Fill" x:Name="blogImage" /> <Border.RenderTransform> <SkewTransform CenterX="250" CenterY="0" AngleX="0" AngleY="350" /> </Border.RenderTransform> </Border> <Border Width="220" Height="300" BorderThickness="10" CornerRadius="10" BorderBrush="OldLace"> <Border.Background> <VisualBrush Visual="{Binding ElementName=blogImage}"> <VisualBrush.Transform> <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="200" CenterY="150" /> </VisualBrush.Transform> </VisualBrush> </Border.Background> <Border.OpacityMask> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="Black" /> <GradientStop Offset="0.3" Color="Transparent" /> </LinearGradientBrush> </Border.OpacityMask> <Border.RenderTransform> <SkewTransform CenterX="260" CenterY="0" AngleX="40" AngleY="350" /> </Border.RenderTransform> </Border> </StackPanel> </Window>
Inserted into the SelectFeaturesWindow.xaml.vb element of that Window.xaml file I have:
Namespace Power_Pack_For_Inventor_AddIn Partial Public Class SelectFeaturesWindow Inherits Window Public Sub New() 'InitializeComponent() End Sub Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click MessageBox.Show("Hello World!", "Feature type selection.") Me.Close() End Sub End Class End Namespace
Inside of my Inventor Addin I have a button which when clicked runs this code:
Try Dim oDoc As Document = g_inventorApplication.ActiveDocument 'Show the WPF Form! Dim selectFeaturesFrm As New SelectFeaturesWindow Dim helper As New WindowInteropHelper(selectFeaturesFrm) helper.Owner = New IntPtr(g_inventorApplication.MainFrameHWND) selectFeaturesFrm.ShowDialog() Catch ex As Exception End Try
and all looks fine. The code builds, the addin loads and I can click the button in my ribbonbar.
The problem is that when the Window loads it looks like this inside of Inventor:
A big ol' screen of white nothing.
If I look in the designer inside of Visual Studio I can clearly see it working though:
EDIT: As I typed this out, I changed one thing and it started working:
I changed the uncommented the InitializeComponent() having previously modified the class inside of the XAML from this:
<Window x:Class="SelectFeaturesWindow"
To this:
<Window x:Class="Power_Pack_For_Inventor_AddIn.SelectFeaturesWindow"
And lo and behold it started working.
I could have not bothered with this post at all now that it is working but I figured it may help others like myself who are just starting
to delve into WPF with Inventor to pay attention to these small details.
Alex Fielder
Inventor Expert
https://github.com/alexfielder/
LinkedIn - Github Inventor Extension Server - Bonkers polygon iLogic thing
Top ten iLogic Tips - API Shortcut In Google Chrome - Assembly Extrusion Example
Solved! Go to Solution.