1

with lookless controls I can add a dependency property like this:

public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("CommandName"), typeof(ICommand), typeof(controlType));

public ICommand Command
{
   get { return (ICommand)GetValue(CommandProperty);}
   set {this.SetValue(CommandProperty,value);}
}

the style:

<Style BasedOn="{StaticResource {x:Type ContentControl}}" TargetType="{x:Type local:ControlType}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ControlType}">
                <Grid x:Name="titleGrid" DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                        <local:DSMoveThumb
                            Title="thumb"/>
                        <button Command={TemplateBinding Command}/>
                        <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Hidden">
                            <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" />
                        </ScrollViewer>
                    </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

so that I can bind to it like this:

<local:control CommandName={Binding ViewModelCommand} />

I would like to do the same thing but for a double click event on the thumb part of the style but i am having a hard time figuring it out. Any input would be appreciated.

  • You don't bind to events but register a callback. This callback is then invoked by the event delegate. For controls you would usually use Routed Events. An Event Trigger can listen to this events and manipulate the control's visual (e.g., of a `ControlTemplate`). What do you try to achieve? – BionicCode Oct 21 '19 at 21:11
  • [Routed Events Overview](https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/routed-events-overview), [`EventSetter`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.eventsetter?view=netframework-4.8#examples), [`EventTrigger`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.eventtrigger?view=netframework-4.8#examples). – BionicCode Oct 21 '19 at 21:26
  • well I suppose I dont need to bind to it but I do need to expose a double click event. The point it that we are emulating a desk top. the lookless control is basically a redhat window. all i need is a double click event on the title bar "thumb" of the window so that the desktop code behind will know when its been double clicked. – dataContexual Oct 22 '19 at 12:28
  • `Control` exposes a `Control.MouseDoubleClick` and a `Control.PreviewMouseDouble` Routed Event. You have several options now depending on your control or developing context (see links above): you can attach an event handler directly to the title bar in your XAML code or use an `EventTrigger`. Or tackle it from code-behind (C#). In case you have access to the code-behind of the control that is patent of the title bar, you can override the `OnApplyTemplate()` member and call `GetTemplateChild(string)` to get the named tab bar and register a handler to it. It depends on your concrete situation... – BionicCode Oct 22 '19 at 15:53
  • From a parent element you can use one of the overloads e.g., [`AddHandler(RoutedEvent, Delegate, Boolean)`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.uielement.addhandler?view=netframework-4.8#System_Windows_UIElement_AddHandler_System_Windows_RoutedEvent_System_Delegate_System_Boolean_) to subscribe to any desired Routed Event of a child element. Preferably use the preview (tunneling) versions of framework Routed Events. – BionicCode Oct 22 '19 at 16:32
  • OK thank you BionicCode. Ill get something figured out with that info. – dataContexual Oct 22 '19 at 17:49

0 Answers0