Revit Form Issue

Revit Form Issue

mitch9TZZY
Participant Participant
729 Views
9 Replies
Message 1 of 10

Revit Form Issue

mitch9TZZY
Participant
Participant

Hi all,

 

I am very new to C# but I'm trying to get into it. Forgive me if this topic has been discussed multiple times. I am trying to create a simple form in Revit that gets activated with an IExternalCommand. I am running into an issue that I cannot seem to figure out with the InitializeComponent(); line of code in the .xaml.cs code.

Here is the form creation:

<Window x:Class="Detail_Line_Creation.LineStylesWindow"
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:Detail_Line_Creation"
mc:Ignorable="d"
Title="Available Line Styles" Height="400" Width="300">
<Grid>
<ListBox Name="LineStyleList" Margin="10"/>
</Grid>
</Window>

 

And here is my xaml.cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Detail_Line_Creation
{
/// <summary>
/// Interaction logic for UserControl2.xaml
/// </summary>
public partial class LineStylesWindow : Window
{
public LineStylesWindow(List<string> lineStyleNames)
{
InitializeComponent();
LineStyleList.ItemsSource = lineStyleNames;
}
}
}

 

I get the CS0103 error code for the InitializeComponent(); as well as for the LineStyleList.

Could anyone help shed some light on what I need to do here? I believe I have all the correct references and assemblies loaded in.

 

Thanks so much.

0 Likes
Accepted solutions (1)
730 Views
9 Replies
Replies (9)
Message 2 of 10

Mohamed_Arshad
Advisor
Advisor

Hi @mitch9TZZY 

 

From your query I can understand that you have converted the UserControl to Window. So you can the below steps

  1. Close the Visual Studio.
  2. Delete the bin and obj folders.
  3. if you find .user file at the project location, kindly delete that as well.

Try Build project. if not possible to build I have created a sample project attached with this query. Kindly download and check the source code. I use Revit Version 2024. 

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 10

mitch9TZZY
Participant
Participant

Hi Mohamed,

 

Thanks for the response. Yes you are correct, I followed some guidance to convert the usercontrol to window. 

I had found the suggestions you mentioned and I have already tried those steps, but with no success unfortunately.

I have also looked at your .xaml.cs file and see that it is exactly the same as mine, but when I open yours in VS there are no errors on it. I can't figure out why though, as if I copy and paste your code into my xaml.cs file, it still throws the same error.

 

Any ideas?

Message 4 of 10

Mohamed_Arshad
Advisor
Advisor

Hi @mitch9TZZY 

If possible can you send the project, So that I can check here. I'm thinking that issue must be in the csprog file.


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 5 of 10

mitch9TZZY
Participant
Participant

Certainly, I am very new to this, so I think everything is quite a mess 🙂 Thanks for your time, really appreciate it!

Message 6 of 10

Mohamed_Arshad
Advisor
Advisor

Hi @mitch9TZZY 

Which Revit version you're using  ?


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 10

Mohamed_Arshad
Advisor
Advisor

Hi @mitch9TZZY 

 

I got your problem, Your trying to create plugin for Revit 2025 right ?


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 8 of 10

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @mitch9TZZY 

 

I too start from the scratch, So I appreciate asking questions.

So you problem was .NET Framework. Till Revit 2024 we used .NETFramework. From Revit  2025 it was moved to .NET 8.0. So you need to use .NET Template when we create new project in the visual studio. Kindly check the below attached image.

 

Reference Image

Mohamed_Arshad_0-1744274498086.png

 

1. Use the below settings for csproj.

<PropertyGroup>
	<TargetFramework>net8.0-windows</TargetFramework>
	<ImplicitUsings>enable</ImplicitUsings>
	<Nullable>enable</Nullable>
	<UseWPF>true</UseWPF>
	<LangVersion>latest</LangVersion>
</PropertyGroup>

2. Double click the project in the visual studio and paste the settings. Kindly check the below snip

Mohamed_Arshad_2-1744274915665.png

 

3. Create WPF and add backend then check it will work. Hope this will works 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 9 of 10

mitch9TZZY
Participant
Participant

Thank you so much for your assistance Mohamed, I really appreciate it.

I haven't gotten it working 100% yet, but you have put me on the right track, thank you 🙂

I think I know what I need to do now... Have a great day and thank you again!

Message 10 of 10

Mohamed_Arshad
Advisor
Advisor

Hi @mitch9TZZY 

Thank you and Happy coding 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes