A community member has associated this post with a similar question:
WPF in AppDomain and System.Runtime.Remoting.RemotingException

Only moderators can edit this content.

WPF User Control without App.xaml (DLL)

Code Wanderer 396 Reputation points
2020-03-12T11:26:50.537+00:00

I created c++ DLL project where I use WPF as GUI. I wanted do it simple as much possible, therefore I use only WPF as DLL without app.xaml (application framework) and use only UserControl and display it on windows.

Problem arise when Dispatcher and DependencyProperty is called:

this.Dispatcher.BeginInvoke(...);

or

b_Text = val; // b_Text is DependencyProperty

those codes does nothing, GUI is not updated and Dispatcher not invoke a function.

I guess, it is because there is not Application framework, which working with DependencyProperty and invoke Dispatcher? Am I right?


Update

here is the code:

C#

namespace PluginUCTest_GUI
{
    public class app_control : UserControl
    {
        public app_control()
        {
            m_dp = this;
        }
        private app_control m_dp = null;
        public app_control Instance { get { return m_dp; } }
        private void SetTempo(double val)
        {
            b_Tempo_ = val.ToString() + " BPM";
        }

        public void mf_SetTempoT(double val)
        {
            SetTempo(val);
            //this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,  new delegates.del_double(SetTempo), val);
        }

public string b_Tempo_
        {
            get { return (string)GetValue(b_Tempo_Property); }
            set { SetValue(b_Tempo_Property, value); }
        }
        public static readonly DependencyProperty b_Tempo_Property = DependencyProperty.Register(
            "b_Tempo_", typeof(string), typeof(app_control), new PropertyMetadata("0 BPM"));
    }
}

--
namespace PluginUCTest_GUI
{
public partial class uc_main_view : UserControl
{
public uc_main_view()
{
InitializeComponent();
}
private app_control dp_object;
public void mf_AddControl(ref app_control uc)
{
dp_object = uc;
this.DataContext = dp_object;
}
}
}

--
In xaml

<TextBlock Text=&#34;{Binding b_Tempo_}&#34; Grid.Column=&#34;1&#34; VerticalAlignment=&#34;Center&#34;/>

In C++ I call

app_control->mf_SetTempoT(x);

Update 2
I forgot add, when GUI is displayed all DependencyProperties are displayed as default, that means "0 BPM" is displayed from b_Tempo_ but not updated, when called from C++

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
{count} votes