首页 > 解决方案 > 事件作为依赖属性 wpf

问题描述

使用外观控件,我可以添加一个依赖属性,如下所示:

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);}
}

样式:

<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>

这样我就可以像这样绑定它:

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

我想做同样的事情,但是对于样式的拇指部分的双击事件,但我很难弄清楚。任何输入将不胜感激。

标签: c#wpfxamleventslookless

解决方案


推荐阅读