Page 1 of 1

EventSetter in Style

Posted: 23 Aug 2022, 00:57
by colin14321
Hi there,

I was wondering if there is support for System.Windows.EventSetter?

I am currently trying to have an EventSetter inside of a Style. If EventSetter is not available, is there another simple way to do this inside of a style?

Code snippet:
 <TreeView.ItemContainerStyle>
                    <Style TargetType="TreeViewItem" BasedOn="{StaticResource TreeViewItem}">
                        <EventSetter Event="Loaded" Handler="TreeViewItem_Loaded"/>
                        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="PointTree_MouseLeftButtonDown"/>
                        <EventSetter Event="Expanded" Handler="PointTree_Expanded"/>
                    </Style>
</TreeView.ItemContainerStyle>
                
Thank you!

Re: EventSetter in Style

Posted: 23 Aug 2022, 11:31
by sfernandez
Hi,

Unfortunately EventSetter is not implemented in Noesis, it was not requested before so could you please add a ticket to our bugtracker about it?

An alternative to EventSetters is to bind to commands exposed in your viewmodel. This can be done in a style by using our StyleInteraction extension.
<TreeView.ItemContainerStyle>
  <Style TargetType="TreeViewItem" BasedOn="{StaticResource TreeViewItem}">
    <Setter Property="noesis:StyleInteraction.Triggers">
      <Setter.Value>
        <noesis:StyleTriggerCollection>
          <b:EventTrigger EventName="Loaded">
            <b:InvokeCommandAction Command="{Binding ItemLoadedCommand}"/>
          </b:EventTrigger>
          <b:EventTrigger EventName="PreviewMouseLeftButtonDown">
            <b:InvokeCommandAction Command="{Binding ItemClickedCommand}"/>
          </b:EventTrigger>
          <b:EventTrigger EventName="Expanded">
            <b:InvokeCommandAction Command="{Binding ItemExpandedCommand}"/>
          </b:EventTrigger>
        </noesis:StyleTriggerCollection>
      </Setter.Value>
    </Setter>
  </Style>
</TreeView.ItemContainerStyle>

Re: EventSetter in Style

Posted: 23 Aug 2022, 20:01
by colin14321
Yes no problem! It is under issue #2404. https://www.noesisengine.com/bugs/view.php?id=2404

I will give commands a try.

Thank you!

Re: EventSetter in Style

Posted: 24 Aug 2022, 11:35
by sfernandez
Thanks for the report.