- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 WPF 中制作自定义控件。我仍在学习 TemplateBinding 的详细信息(在自定义控件中大量使用)。
我注意到我似乎无法在 MulitBinding 内部使用 TemplateBinding。
当我尝试这个时:
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource MyMultiConverter}">
<Binding ElementName="PART_AComboBox" Path="SelectedItem"/>
<TemplateBinding Property="MyListOne"/>
<TemplateBinding Property="MyListTwo"/>
</MultiBinding>
</ComboBox.ItemsSource>
我收到此错误:
The value "System.Windows.TemplateBindingExpression" is not of type "System.Windows.Data.BindingBase" and cannot be used in this generic collection.
Parameter name: value
我错过了什么吗?有办法让它工作吗?
这是我正在采取的解决方法,但它是一种黑客:
<ListBox x:Name="ListOne"
ItemsSource="{TemplateBinding MyListOne}"
Visibility="Collapsed" />
<ListBox x:Name="ListTwo"
ItemsSource="{TemplateBinding MyListTwo}"
Visibility="Collapsed" />
<ComboBox.ItemsSource>
<MultiBinding Converter="{StaticResource DictionaryFilteredToKeysConverter}">
<Binding ElementName="PART_TextTemplateAreasHost" Path="SelectedItem"/>
<Binding ElementName="ListOne" Path="ItemsSource"/>
<Binding ElementName="ListTwo" Path="ItemsSource"/>
</MultiBinding>
</ComboBox.ItemsSource>
我将 ListBoxes 绑定(bind)到依赖属性,然后在我的多重绑定(bind)中将一个元素绑定(bind)到列表框的 ItemsSource。
正如我上面所说,这感觉像是一种黑客行为,我想知道是否有正确的方法来使用 TemplateBinding 作为组件之一来执行多重绑定(bind)。
最佳答案
您可以使用:
<Binding Path="MyListOne" RelativeSource="{RelativeSource TemplatedParent}"/>
TemplateBinding
实际上只是上述内容的简化、优化版本。它对于使用地点和方式非常严格(直接在模板内部,没有分层路径等)。
XAML 编译器在对此类问题提供适当的反馈方面仍然相当垃圾(至少在 4.0 中,没有专门为此测试 4.5)。我刚刚有了这个 XAML:
<ControlTemplate TargetType="...">
<Path ...>
<Path.RenderTransform>
<RotateTransform Angle="{TemplateBinding Tag}"/>
</Path.RenderTransform>
</Path>
</ControlTemplate>
它编译并执行得很好,但没有将 Tag
中的值绑定(bind)到旋转角度。我窥探了一下,发现该属性(property)已绑定(bind),但为零。直觉上(经过多年处理这种烦恼)我将其更改为:
<ControlTemplate TargetType="...">
<Path ...>
<Path.RenderTransform>
<RotateTransform Angle="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"/>
</Path.RenderTransform>
</Path>
</ControlTemplate>
而且效果很好。
关于.net - 将 MultiBinding 与 TemplateBindings 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342644/
MultiBinding 到背景属性不起作用。转换后,背景只是变成系统的默认颜色,而不是我在 MultiValueConverter 中设置的颜色。其他一切都已正确设置。我的 MultiBinding
让我们考虑一种动物 Model如下: public class Animal { public string name { set; get; } public int age { s
下面的代码将列宽:Samp1.ActualWidth 和 Samp2.ActualWidth 绑定(bind)到 StatName.Width。请参阅:Bind DataGrid Column Wid
我在尝试将现有 XAML 转换为 MultiBinding 时遇到问题。 当前代码(需要替换)是 我现在拥有的:
我正在尝试转换一些单位。Convertback 函数应如何处理以下内容。获得以下 XAML。标签设置为我的 ViewModel 中的唯一对象。 这种风格...
我想做类似的事情 post但使用MultipleBindings。 所以是这样的:
以下代码用于绑定(bind) ListView,但对 ListView 的任何更改都不会返回到内存中的数据结构。当我有标准绑定(bind)时,它可以双向工作,但不能使用多重绑定(bind)。我需要使用
在 中设置样式(假设转换器返回红色)
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question
我正在尝试使用标签控件在 XAML 中显示一个字符串。以下是我的 XAML 代码:
如何跳过更新MultiBinding的一些子绑定(bind)?我已经在代码隐藏中定义了一个 MultiBinding ,它需要两次读取-仅属性和一个普通属性生成单个值。在 ConvertBack 的情
我正在 wpf TreeView 上使用上下文菜单,并且我几乎可以满足我的需求。在解释问题之前,让我先解释一下上下文菜单的 XAML 定义的作用。 对于上下文菜单中的每个菜单项,我们都有一个命令,该命
使用 com.google.inject.multibindings.Multibinder 时,我对泛型有点困惑如下: interface MessageParser { fun accept(
我知道我可以使用特定注释进行 Guice 多重绑定(bind),如下所示 Multibinder.newSetBinder(binder(), Bound.class, Annotation.clas
基本上我需要知道的是如何发送 HierarchicalDataTemplate 的来源绑定(bind)到一个绑定(bind)中,这就是我所拥有的:
我创建了一个内联 MultiBinding使用 this post作为引用。更具体地说,我正在使用 Christian Myksvoll 的答案来创建自定义绑定(bind)。我的类(class)看起来
我有一个内置动态语言切换的应用程序。根据所选的文化,整个应用程序中的字符串都会发生变化。翻译后的字符串及其原始值来自资源文件。我使用绑定(bind)将资源值附加到按钮、标签等。大部分绑定(bind)发
我想做的很简单。我有一个窗口,我希望将标题绑定(bind)到两个不同的属性。每次属性之一更改时,标题都应更新。 我首先尝试的但没有成功 错
我创建了一个自定义的 MultiValue Converter 来在 MultiBinding 到 TextBox 时执行一些逻辑;但是我不想使用 convertBack,因为绑定(bind)值没有编
我这辈子都做不到。我需要从文本 block 中的一对时间跨度对象显示 hh:mm,但它无法正常工作。这是我目前所拥有的:
我是一名优秀的程序员,十分优秀!