View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0003648 | NoesisGUI | C++ SDK | public | 2024-08-19 15:32 | 2026-04-27 12:17 |
| Reporter | FrancoisRecisio | Assigned To | sfernandez | ||
| Priority | high | Severity | minor | ||
| Status | feedback | Resolution | open | ||
| Product Version | 3.2.4 | ||||
| Target Version | 3.2.14 | ||||
| Summary | 0003648: DataEventTrigger never triggers in the first "frame" | ||||
| Description | Related post https://www.noesisengine.com/forums/viewtopic.php?t=3428 | ||||
| Steps To Reproduce | Add CustomCb.cpp and CustomCb.h in the XamlPlayer solution, with RegisterComponent<CustomCb>(); in RegisterComponents (Main.cpp line 168) | ||||
| Attached Files | CustomCb.cpp (1,378 bytes)
#include "CustomCb.h"
#include <NsGui/IntegrationAPI.h>
#include <NsGui/Uri.h>
#include <NsCore/ReflectionImplement.h>
ViewModel::ViewModel()
: m_elements(Noesis::MakePtr<Noesis::ObservableCollection<ViewModel::Element>>())
{
m_elements->Add(Noesis::MakePtr<ViewModel::Element>());
}
CustomCb::CustomCb()
{
Initialized() += MakeDelegate(this, &CustomCb::OnInitialized);
InitializeComponent();
m_viewModel = Noesis::MakePtr<ViewModel>();
}
void CustomCb::InitializeComponent()
{
Noesis::GUI::LoadComponent(this, "Custom.xaml");
}
void CustomCb::OnInitialized(Noesis::BaseComponent*, const Noesis::EventArgs&)
{
SetDataContext(m_viewModel);
}
void CustomCb::OnMouseLeftButtonDown(const Noesis::MouseButtonEventArgs&)
{
m_viewModel->m_elements->Add(Noesis::MakePtr<ViewModel::Element>());
for (int i = 0; i < m_viewModel->m_elements->Count(); ++i)
{
m_viewModel->m_elements->Get(i)->customEvent(this, Noesis::EventArgs::Empty);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
NS_BEGIN_COLD_REGION
NS_IMPLEMENT_REFLECTION(ViewModel::Element)
{
NsEvent("CustomEvent", &Element::customEvent);
}
NS_IMPLEMENT_REFLECTION(ViewModel)
{
NsProp("Elements", &ViewModel::GetElements);
}
NS_IMPLEMENT_REFLECTION_(CustomCb, "Custom")
NS_END_COLD_REGION
CustomCb.h (947 bytes)
#pragma once
#include <NsCore/ReflectionDeclare.h>
#include <NsGui/ObservableCollection.h>
#include <NsGui/ContentControl.h>
class ViewModel final: public Noesis::BaseComponent
{
public:
struct Element final : public Noesis::BaseComponent
{
Noesis::EventHandler customEvent;
NS_DECLARE_REFLECTION(Element, BaseComponent)
};
ViewModel();
Noesis::ObservableCollection<Element>* GetElements() const { return m_elements; }
Noesis::Ptr<Noesis::ObservableCollection<Element>> m_elements;
NS_DECLARE_REFLECTION(ViewModel, BaseComponent)
};
class CustomCb final : public Noesis::ContentControl
{
public:
CustomCb();
private:
void InitializeComponent();
void OnInitialized(Noesis::BaseComponent*, const Noesis::EventArgs&);
void OnMouseLeftButtonDown(const Noesis::MouseButtonEventArgs& e) override;
Noesis::Ptr<ViewModel> m_viewModel;
NS_DECLARE_REFLECTION(CustomCb, ContentControl)
};
Demo.xaml (1,905 bytes)
<ContentControl x:Class="Custom"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">
<Grid>
<Grid.Resources>
<ResourceDictionary>
<DataTemplate x:Key="Element">
<Rectangle x:Name="Rectangle" Fill="White" Width="40" Height="40" Margin="20">
<Rectangle.Resources>
<Storyboard x:Key="CustomAnim">
<DoubleAnimation
Storyboard.TargetName="Rectangle"
Storyboard.TargetProperty="(Rectangle.Opacity)"
BeginTime="0:0:0" From="0" To="1" Duration="0:0:1" />
</Storyboard>
</Rectangle.Resources>
<b:Interaction.Triggers>
<noesis:DataEventTrigger Source="{Binding}" EventName="CustomEvent">
<b:ControlStoryboardAction Storyboard="{StaticResource CustomAnim}" />
</noesis:DataEventTrigger>
</b:Interaction.Triggers>
</Rectangle>
</DataTemplate>
</ResourceDictionary>
</Grid.Resources>
<ItemsControl ItemsSource="{Binding Elements}" ItemTemplate="{StaticResource Element}" Focusable="False">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</ContentControl>
| ||||
| Platform | Any | ||||
|
I've been testing the provided sample and the behavior seems correct, because the trigger listening to the item event is not created until the ItemsControl gets measured and items are generated. If I call UpdateLayout() on the View before raising the element event, to allow ItemsControl to generate the new items, then the trigger is properly notified. Isn't that what you expect? |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2024-08-19 15:32 | FrancoisRecisio | New Issue | |
| 2024-08-19 15:32 | FrancoisRecisio | File Added: CustomCb.cpp | |
| 2024-08-19 15:32 | FrancoisRecisio | File Added: CustomCb.h | |
| 2024-08-19 15:32 | FrancoisRecisio | File Added: Demo.xaml | |
| 2024-08-20 10:38 | jsantos | Assigned To | => sfernandez |
| 2024-08-20 10:38 | jsantos | Status | new => assigned |
| 2024-08-20 10:38 | jsantos | Target Version | => 3.2.5 |
| 2024-10-24 16:43 | sfernandez | Target Version | 3.2.5 => 3.2.6 |
| 2024-11-14 17:42 | jsantos | Priority | normal => high |
| 2024-11-22 18:18 | jsantos | Target Version | 3.2.6 => 3.2.7 |
| 2025-01-20 17:43 | jsantos | Target Version | 3.2.7 => 3.2.8 |
| 2025-06-06 12:52 | jsantos | Target Version | 3.2.8 => 3.2.9 |
| 2025-10-02 00:48 | jsantos | Target Version | 3.2.9 => 3.2.10 |
| 2025-10-20 18:25 | jsantos | Target Version | 3.2.10 => 3.2.11 |
| 2026-01-20 17:22 | sfernandez | Status | assigned => feedback |
| 2026-01-20 17:22 | sfernandez | Note Added: 0011724 | |
| 2026-01-20 19:32 | jsantos | Target Version | 3.2.11 => 3.2.12 |
| 2026-01-20 19:55 | jsantos | Target Version | 3.2.12 => 3.2.11 |
| 2026-02-16 16:57 | jsantos | Target Version | 3.2.11 => 3.2.12 |
| 2026-03-04 00:39 | jsantos | Target Version | 3.2.12 => 3.2.13 |
| 2026-04-27 12:17 | jsantos | Target Version | 3.2.13 => 3.2.14 |