Managed configuration: binding in dockpane not working, and Initialize() not called

270
4
Jump to solution
03-20-2024 06:39 AM
BarbaraSchneider2
Occasional Contributor II

I'm experiencing very strange behavior. I have two managed configurations. In the first, everything works fine. In the second, I'm running into the two following problems:

1. The binding in my dockpane is not working. The dockpane is referenced in the Config.daml as follows:

 

 <dockPane id="BiotopApp_View_Dockpanes_DockStart" caption="Objekt starten" className="BiotopApp.View.Dockpanes.DockStartViewModel" dock="group" dockWith="esri_core_projectDockPane">
   <content className="BiotopApp.View.Dockpanes.DockStartView" />
 </dockPane>

 

I define a button in DockStart.xaml as follows:

 

<Button x:Name="btnStart" Content="Objekt starten" Command="{Binding CommandStartObject}" IsEnabled="{Binding CommandStartEnabled}" Background ="LightGreen" HorizontalAlignment="Left" Margin="202,493.4,0,0" Grid.Row="1" VerticalAlignment="Top" Width="108" RenderTransformOrigin="0.776,-0.2" Height="26"/>

 

The code in DockStartViewModel for the button is as follows:

 

internal ICommand CommandStartObject
{
	get
	{
		return new RelayCommand(async (args) => await StartObjectAsync(), () => true);
	}
}

 

2. When I start the managed configuration, the following method is never called:

 

internal class BiosModule : Module
{
    protected override bool Initialize()
    {		
	return base.Initialize();		
    }
    ...

 

What am I overlooking? I am doing exactly the same things in both Managed Configurations.

One last question: how does the .xaml know to which class it is bound? It is not the following line of code:

 

d:DataContext="{Binding Path=DockStartViewModel}">

 

 

0 Kudos
1 Solution

Accepted Solutions
BarbaraSchneider2
Occasional Contributor II

@GKmieliauskas: Thank you for your reply!

1. I found out what caused the first problem. The implementation for the command in the ViewModel must be public, not internal:

public ICommand CommandStartObject
{
	get
	{
		return new RelayCommand(async (args) => await StartObjectAsync(), () => true);
	}
}

 2. You solved the second problem: if autoLoad in the Config.daml, is set to true, the function Initialize() in the module is called:

 <insertModule id="BiotopApp_Module" className="BiosModule" autoLoad="true" caption="BiosModule">

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

I would suggest you to check dockpane 'classname' and dockpane's content 'classname' paths.

For dockpane viewmodel class is specified as 'classname' value and view class - as content 'classname' value.

DataContext is set inside dockpane's internal code.

 

I have noticed that you change module class name from Module1 to BiosModule. Have you changed Module class name in daml?

- <insertModule id="*******_Module" className="Module1" autoLoad="false" caption="Module1">

Setting autoLoad to true could help too.

0 Kudos
BarbaraSchneider2
Occasional Contributor II

@GKmieliauskas: Thank you for your reply!

1. I found out what caused the first problem. The implementation for the command in the ViewModel must be public, not internal:

public ICommand CommandStartObject
{
	get
	{
		return new RelayCommand(async (args) => await StartObjectAsync(), () => true);
	}
}

 2. You solved the second problem: if autoLoad in the Config.daml, is set to true, the function Initialize() in the module is called:

 <insertModule id="BiotopApp_Module" className="BiosModule" autoLoad="true" caption="BiosModule">
0 Kudos
CharlesMacleod
Esri Regular Contributor

Modules are lazy loaded when autoLoad=false - the default. Thus, the module initialize will fire when the first "action" occurs that triggers module loading - for example - a button click on the ribbon (which is the most common) or a previously open dockpane is re-opened at the beginning of the session. At that time, before _anything_ else, the Module is constructed (eg new Module1() {}) and Initialize is called. Then everything else. 

Obviously, the coding pattern for Initialize can get a bit tricky when autoLoad=false because the timing of when it will occur within a given session will change (depending on when the first action that triggers module loading occurs). Setting autoLoad=true means that the Module will always load at the same time at the beginning of the session regardless of when the first action or "use" occurs. 

0 Kudos
BarbaraSchneider2
Occasional Contributor II

Hi Charles,

thank you for the clarification! I wasn't aware of it. This is very good to know, and it also explains why in one of my managed configurations, Initialize() was called, and in the other not. In both of them, autoLoad was set to false.

Actually, why is the default for autoLoad = false? Wouldn't it be easier for developers if it was true? At least, I wouldn't have run into my problem explained above...

0 Kudos