Custom node for launching a window with a user interface

Hi all,
I’m trying to create note, that opens a new window with user interface. I have achieved the desired result, but the node has an input parameter, that I didn’t set. I just started learning C#. Tell me please, is it possible to get rid of unnecessary input parameters?

Code for window with user interface

using System.Windows;


namespace TestNodes
{
    /// <summary>
    /// TestUI.xaml
    /// </summary>
    public partial class TestUI : Window
    {
        public TestUI()
        {
            InitializeComponent();
        }

        private void ok_buttom_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void cencel_buttom_Click(object sender, RoutedEventArgs e)
        {
            DialogResult=false;
            Close();
        }
    }

Code of the method, that launches the window with the user interface.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace TestNodes
{
    public class UserInterface
    {
        public List<Object> UI_Interface()
        {
            List<Object> ListReturn = new List<Object>();
            TestUI window = new TestUI();

            var res = window.ShowDialog();
            if (!res.HasValue && res.Value)
                window.Close();

            ListReturn.Add(window.textbox.Text);
            return ListReturn;
        }

    }
}

This node in Dynamo.
image

I have studied a lot of information and have not found a way to get rid of this parameter, please help me.

@David.Malinovsky ,

i did some stuff in python

Yes, I have seen, that it is possible to implement UI in python. But my goal now is to implement UI in C#.

@David.Malinovsky ,

Is your goal to learn C# and if so, what is dynamo giving you that C# wouldn’t?
Dynamo, Python and pyRevit all play nicely together.
pyRevit plays nicely with .vbs and cs.
C# is big and bad, and can do it all by itself.

If you are heading into C#, I’d just jump into that for the whole app. A learning curve for sure, but probably simpler in the end more robust. Just a heads up, deployment and maintenance of C# as a Revit add-in is a pita for a small office.

But if you are just after a nice basic UI stuff - you can’t beat pyRevit’s forms. Robust and simple to implement.

I understand what you’re talking about. But it’s just a piece of something bigger. It is important to me that the UI is implemented as a node for Dynamo created in C#.

Sample Github repo of how to create a window in C# here:

2 Likes

So, that is a zero-touch node you’ve created?
And you’ve taken a look at this?
Revit Add-Ons: Video: Creating a Dynamo User Interface (UI) with XAML and C# (revitaddons.blogspot.com)

This is what I was looking for. Thank you very much! You have helped me a lot!

The solution to the problem was in one line

        public TestUI()
        {
            InitializeComponent();
            DataContext = this;
        }