How to send event from view to VM?
I want to send event from View to VM
I know the build-in control have some Command can do this in xaml, such Button.Click, but how UserControl? How fire event in MyView.h?
Code: Select all
MyView.xaml
<Button TouchDown="HandeTouchDown" TouchUp="HandleTouchUp">
MyView.h
class
{
//connect event
virtual bool ConnectEvent() override;
void HandleTouchDown()
{
//let vm konw touch down
}
void HandleTouchUp()
{
if(index == touchDevice && TouchTime > 0.5f)
{
HnadleLongPress()
}
//let vm konw touch up
}
void HandleLongPress()
{
//let VM know longpress.
}
}
class ViewModel : public UObject
{
void HandleLongPress()
{
}
}
Re: How to send event from view to VM?
Does NoesisGUI has a module can convert event to command such as System.Windows.Interactivity ?
Re: How to send event from view to VM?
Hi UE4,
Yes, we do. It's in a class named NoesisGUIExtensions.EventToCommand that exposes several dependency properties. You can find an example of its use in the Menu3D sample. Here's a xaml that uses it:
https://github.com/Noesis/Tutorials/blo ... tMenu.xaml
Hope this helps.
Yes, we do. It's in a class named NoesisGUIExtensions.EventToCommand that exposes several dependency properties. You can find an example of its use in the Menu3D sample. Here's a xaml that uses it:
https://github.com/Noesis/Tutorials/blo ... tMenu.xaml
Hope this helps.
Re: How to send event from view to VM?
Confused about the Menu3D sample UE4 version, no EventToCommand defined in code such as in C#, but all works well.Hi UE4,
Yes, we do. It's in a class named NoesisGUIExtensions.EventToCommand that exposes several dependency properties. You can find an example of its use in the Menu3D sample. Here's a xaml that uses it:
https://github.com/Noesis/Tutorials/blo ... tMenu.xaml
Hope this helps.
Re: How to send event from view to VM?
EventToCommand is part of the native NoesisGUI runtime, so it works out of the box.
Re: How to send event from view to VM?
Hi UE4,
Yes, we do. It's in a class named NoesisGUIExtensions.EventToCommand that exposes several dependency properties. You can find an example of its use in the Menu3D sample. Here's a xaml that uses it:
https://github.com/Noesis/Tutorials/blo ... tMenu.xaml
Hope this helps.
Code: Select all
<ItemsControl ItemsSource="{Binding SpellList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="800" Height="200"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:TouchButton x:Name="Spell_0"
noesis:EventToCommand.Event="TouchDown"
noesis:EventToCommand.Command="{Binding SpellTouchDown}"
noesis:EventToCommand.CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Name}"
Width="120" Height="120" Canvas.Left="300" Canvas.Top="550"></local:TouchButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Second, the EventToCommand will not work in DataTemplate
Re: How to send event from view to VM?
Hi,
I've tried this modified version of your xaml that doesn't use your custom TouchButton:
I have a Spell class that exposes a property of type ICommand called SpellTouchDown and the data context has a property that is a collection of spells named SpellList. When I click the button SpellTouchDown is called on the spell, and the string "Spell_0" is passed as the argument. Is that the behavior you were expecting?
As for the child item position, do you mean that Canvas.Left="300" Canvas.Top="550" do nothing? The containing panel is a WrapPanel, not a Canvas, so those dependency properties won't have an effect.
I've tried this modified version of your xaml that doesn't use your custom TouchButton:
Code: Select all
<ItemsControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:noesis="clr-namespace:NoesisGUIExtensions"
ItemsSource="{Binding SpellList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="800" Height="200"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="Spell_0"
noesis:EventToCommand.Event="Click"
noesis:EventToCommand.Command="{Binding SpellTouchDown}"
noesis:EventToCommand.CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Name}"
Width="120" Height="120">
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
As for the child item position, do you mean that Canvas.Left="300" Canvas.Top="550" do nothing? The containing panel is a WrapPanel, not a Canvas, so those dependency properties won't have an effect.
Re: How to send event from view to VM?
still have some problem, https://drive.google.com/open?id=1PB9CJ ... yYQZyj95wjHi,
I've tried this modified version of your xaml that doesn't use your custom TouchButton:
I have a Spell class that exposes a property of type ICommand called SpellTouchDown and the data context has a property that is a collection of spells named SpellList. When I click the button SpellTouchDown is called on the spell, and the string "Spell_0" is passed as the argument. Is that the behavior you were expecting?
As for the child item position, do you mean that Canvas.Left="300" Canvas.Top="550" do nothing? The containing panel is a WrapPanel, not a Canvas, so those dependency properties won't have an effect.
additional question about to the demo projection: if the VM has TArray<FString> DisplayTextList; how can I binding it to button? I mean its not a struct element, just a basic element.
Re: How to send event from view to VM?
how to convert event's param to command's param?
Command's param in Ueral is a UObject, NoesisCreateBaseComponentForUObject(BaseComponent); if there is a JoystickControl, evenry time I TouchMove on joystick, a command fired. and a UObject created? or reuse the UObject? I find the these Uobject's name are different.
Command's param in Ueral is a UObject, NoesisCreateBaseComponentForUObject(BaseComponent); if there is a JoystickControl, evenry time I TouchMove on joystick, a command fired. and a UObject created? or reuse the UObject? I find the these Uobject's name are different.
Re: How to send event from view to VM?
solved it by:
Code: Select all
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left" Value="{Binding Offset.X}" />
<Setter Property="Canvas.Top" Value="{Binding Offset.Y}"/>
<Setter Property="Canvas.Width" Value="{Binding DrawSize.X}"/>
<Setter Property="Canvas.Height" Value="{Binding DrawSize.Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
Who is online
Users browsing this forum: No registered users and 8 guests