wpf - 如何在行为中将绑定添加到 xaml 绑定?
问题描述
我有一个 xaml 接口的行为:
<i:Interaction.Behaviors>
<b:ChartCanvasItemBehavior
Source="{Binding MovieUri}"
Timeline="{Binding Path=Timeline, ElementName=ChartCanvasRightPanel, Mode=OneWayToSource}"
/>
</i:Interaction.Behaviors>
该行为创建了一个装饰器,它执行以下操作:
public double Timeline
{
get { return (double)GetValue(TimelineProperty); }
set { SetValue(TimelineProperty, value); }
}
// Using a DependencyProperty as the backing store for Timeline. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TimelineProperty =
DependencyProperty.Register("Timeline", typeof(double), typeof(MovieControlForChartCanvas), new UIPropertyMetadata(0.0));
为了将两者联系起来,我有:
var bindingMovieTime = new Binding
{
Source = mc,
Path = new PropertyPath(MovieControlForChartCanvas.TimelineProperty)
};
BindingOperations.SetBinding(this, iTimelineProperty, bindingMovieTime);
#region [Dependency Properties used to bind to the MovieControlForChartCanvas]
// These dependecy properties have to be DIFFERENT then the dependency properties used for the ChartCanvasItemBehavior xaml interface.
// Using the same dependecy property for both bindings to the MovieControl and the Xaml interface results in losing one of the first bindings (i.e., the xaml binding).
public double iTimeline
{
get { return (double)GetValue(iTimelineProperty); }
set { SetValue(iTimelineProperty, value); }
}
// Using a DependencyProperty as the backing store for iTimeline. This enables animation, styling, binding, etc...
public static readonly DependencyProperty iTimelineProperty =
DependencyProperty.Register("iTimeline", typeof(double), typeof(ChartCanvasItemBehavior), new PropertyMetadata(0.0,
(s, e) =>
{
ChartCanvasItemBehavior d = s as ChartCanvasItemBehavior;
d.Timeline = (double)e.NewValue;
}
));
#endregion
public double Timeline
{
get { return (double)GetValue(TimelineProperty); }
set { SetValue(TimelineProperty, value); }
}
// Using a DependencyProperty as the backing store for Timeline. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TimelineProperty =
DependencyProperty.Register("Timeline", typeof(double), typeof(ChartCanvasItemBehavior ), new PropertyMetadata(0.0));
这似乎需要行为和装饰者之间的第二个属性。如果我对行为接口和行为到装饰器接口都使用一个属性,则对该行为的第一个分配(即来自 xaml)将被与装饰器的绑定覆盖。
这可以在多重绑定的行为中仅使用一个依赖属性来完成吗?如果是这样,怎么做?
换句话说,是否可以在行为中使用一个依赖属性作为 xaml 和装饰器的接口?(多重绑定?)
感谢您的任何建议。
解决方案
推荐阅读
- python - 如何为特定页面设置页面大小
- python - Python - Kivy:在 RecycleView 中垂直滚动不能使用向上/向下箭头键
- json - 纽约时间 API 的正确 URL
- kubernetes - Kubernetes手表的正确使用方法
- html-email - gmail中的电子邮件签名将图像显示为附件
- oracle - 具有不同值的报告区域上的 oracle apex 工具提示
- autodesk-forge - 使用 Forge Webhooks API 跟踪模型翻译进度
- python - 查询 RelatedManager 对象
- java - TestNG 未显示在首选项中-JDK 1.8
- javascript - Jquery - Ajax 点击一个 href 触发器