v3 (DelegateCommand) Command binding implementation
Posted: 22 Jul 2020, 16:07
I am trying to upgrade NoesisGUI from v2.2.x to v3.0.x for my project.
After several days survey and trying.
I found that DelegateCommand instance setup for command binding have something different.
I created a test user-control (Test3Window)
Here is my code-behind class and data-model class
If I move "#if NOESISGUI #endif" block, codes of setup DelegateCommand after assign "DataContext = model",
then commands did not work in v3, but it worked in v2.
I wanna know if this is necessary to setup DelegateCommand instances BEFORE assign DataContext for proper command-binding in XAML files?
After several days survey and trying.
I found that DelegateCommand instance setup for command binding have something different.
I created a test user-control (Test3Window)
Code: Select all
<Grid>
<StackPanel>
<Button Content="Command-1"
Command="{Binding Command1}"
Height="40" Margin="40"/>
<Button Content="Command-2"
Command="{Binding Command2}"
Height="40" Margin="40"/>
</StackPanel>
</Grid>
Code: Select all
public class Test3Model
{
public DelegateCommand Command1 { get; set; }
public DelegateCommand Command2 { get; set; }
}
public partial class Test3Window : UserControl
{
public Test3Window()
{
Initialized += OnInitialized;
InitializeComponent();
}
#region _Methods
private void InitializeComponent()
{
Noesis.GUI.LoadComponent(this, "Assets/Xamls/Test3Window.xaml");
}
private void OnInitialized(object sender, EventArgs args)
{
var model = new Test3Model();
#if NOESISGUI
model.Command1 = new DelegateCommand(p =>
{
Debug.Log("Command1");
});
model.Command2 = new DelegateCommand(p =>
{
Debug.Log("Command2");
});
#endif
DataContext = model;
}
#endregion
}
If I move "#if NOESISGUI #endif" block, codes of setup DelegateCommand after assign "DataContext = model",
then commands did not work in v3, but it worked in v2.
I wanna know if this is necessary to setup DelegateCommand instances BEFORE assign DataContext for proper command-binding in XAML files?