NotifyArrayChanged in UE Question
Hello, I'd like to ask a question about using NotifyArrayChanged in UE.
I have an Array (PlayBulletBars) as the itemsSource of an ItemsControl. PlayBulletBars is an array of UBulletVisible class.The class UBulletVisible has a FString property named BulletVisible.
And, within the ContentControl that is bound in the ItemTemplate, I bind the Visibility of an image to a property "BulletVisible". Additionally, I added a behavior to this ContentControl that plays an animation when Visibility == {x:Static Visibility.Visible}.
When I modify a specific UBulletVisible in PlayBulletBars within the ViewModel code, I call Noesis::NotifyArrayChanged(this, "PlayBulletBars").
However, the actual behavior is that every time I modify the Visibility of one item(Gain Bullet), all bullet items play the animation.
ItemsControl code
ContentControl Code
ViewModel Code(I use AngleScript)

When Click GainBullet .

So, is it because NotifyArray always updates all items every time? Is there a better way to achieve playing animation only for the item that has its status changed?
I have an Array (PlayBulletBars) as the itemsSource of an ItemsControl. PlayBulletBars is an array of UBulletVisible class.The class UBulletVisible has a FString property named BulletVisible.
And, within the ContentControl that is bound in the ItemTemplate, I bind the Visibility of an image to a property "BulletVisible". Additionally, I added a behavior to this ContentControl that plays an animation when Visibility == {x:Static Visibility.Visible}.
When I modify a specific UBulletVisible in PlayBulletBars within the ViewModel code, I call Noesis::NotifyArrayChanged(this, "PlayBulletBars").
However, the actual behavior is that every time I modify the Visibility of one item(Gain Bullet), all bullet items play the animation.
ItemsControl code
Code: Select all
<ItemsControl x:Name="bar" ItemsSource="{Binding PlayBulletBars}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" Style="{StaticResource Style.BulletBarSlot}">
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Code: Select all
<ControlTemplate x:Key="BulletBarSlot" TargetType="{x:Type ContentControl}">
<ControlTemplate.Resources>
<Storyboard x:Key="GainBulletStoryboard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="bullet">
<EasingDoubleKeyFrame KeyTime="0" Value="-120">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid Width="58" Height="103">
<Image x:Name="bg" HorizontalAlignment="Center" Source="{StaticResource Game/CombatHUD/T_UI_Bullet_Bg}"/>
<Image x:Name="bullet" HorizontalAlignment="Center" Source="{StaticResource Game/CombatHUD/T_UI_Bullet}" Visibility="{Binding BulletVisible}" RenderTransformOrigin="0.5,0.5">
<b:Interaction.Triggers>
<b:DataTrigger Binding="{Binding Visibility, ElementName=bullet}" Value="{x:Static Visibility.Visible}">
<b:ControlStoryboardAction Storyboard="{StaticResource GainBulletStoryboard}"/>
</b:DataTrigger>
</b:Interaction.Triggers>
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
</ControlTemplate>
<Style x:Key="Style.BulletBarSlot" TargetType="{x:Type ContentControl}">
<Setter Property="Template" Value="{StaticResource BulletBarSlot}"/>
</Style>
Code: Select all
UFUNCTION()
void DebugGainBulletBar()
{
for (int Index = 0, Num = PlayBulletBars.Num(); Index < Num; ++Index)
{
UBulletVisible CurBar = PlayBulletBars[Index];
if (CurBar.BulletVisible != "Visible"){
CurBar.BulletVisible = "Visible";
break;
}
}
Noesis::NotifyArrayChanged(this, n"PlayBulletBars");
}

When Click GainBullet .

So, is it because NotifyArray always updates all items every time? Is there a better way to achieve playing animation only for the item that has its status changed?
Re: NotifyArrayChanged in UE Question
Hi!
Instead of notifying the array has changed, could you try notifying the element of the object has changed like this:
Noesis::NotifyChanged(CurBar, “BulletVisible”);
Instead of notifying the array has changed, could you try notifying the element of the object has changed like this:
Noesis::NotifyChanged(CurBar, “BulletVisible”);
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests