c# - 事件作为依赖属性 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} />
我想做同样的事情,但是对于样式的拇指部分的双击事件,但我很难弄清楚。任何输入将不胜感激。
解决方案
推荐阅读
- java - 在单列中显示地址,而不是在自己的列中显示每一行地址
- java - 所需的输出是假,真,假,真。我的结果是错误的,真实的,真实的,真实的。我的代码中是否缺少某些内容?
- android - JetpackCompose Modifier 属性的 aspectRatio(1f) 和 fillMaxSize() 有什么区别
- azure - Azure 应用服务 - 三个可用区中的实例
- docker - 如何在带有许多引号的 Windows Docker 容器中执行 WMI 查询?
- asp.net - 对所有无效属性使用单个错误消息模板
- pandas - 拆垛后按自定义顺序排列列
- python - socket while loop recv 是否会出现未完成的情况?
- hive - Hiveserver2 未启动 - 捕获异常:ZooKeeper 节点 /hiveserver2 尚未准备好
- android - 上传媒体 FTP VS HTTP(Multipart