- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在我的 Xaml 中绑定(bind)几个不同的属性:
<Label Content="{Binding Description}"
Visibility="{Binding Path=DescriptionVisibility,
ElementName=_UserInputOutput}"
FontSize="{Binding Path=FontSizeValue, ElementName=_UserInputOutput}"
HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
public string Description
{
get { return (string)GetValue(DescriptionProperty); }
set { SetValue(DescriptionProperty, value); }
}
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register("Description", typeof(string), typeof(UserControl),
new UIPropertyMetadata(""));
{Binding Description}
{Binding Path=Description, ElementName=_UserInputOutput}
{Binding Path=Description, RelativeSource={RelativeSource Self}}
最佳答案
{RelativeSource Self}
如果您在 Label
上有这样的绑定(bind),则以拥有正在绑定(bind)的属性的对象为目标。它将寻找 Label.Description
,这是不存在的。相反,您应该使用 {RelativeSource AncestorType=UserControl}
.
没有源的绑定(bind)( ElementName
, Source
, RelativeSource
)是相对于 DataContext
, 但是在 UserControls
你应该 avoid setting the DataContext
不要弄乱外部绑定(bind)。
关于wpf - 如何绑定(bind)到 RelativeSource Self?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11995318/
这是代码: item1
我有一个作为 excel 插件运行的 WPF 应用程序,它有这样的可视化树 精益求精 元素主机 WPF 用户控件 WPF 色带条控件 现在,在 excel 中加载插件时,不会启用位于 WPF 功能区栏
我正在使用绑定(bind) RelativeSource与 FindAncestor模式但绑定(bind)不起作用。如何调试并查看它是否能够找到祖先? 最佳答案 使用 Snoop 编辑:您当然可以使用
我正在尝试将 DataGridTextColumn 的背景颜色设置为另一种颜色(如果它是只读的)。我正在使用以下代码这样做:
是 FindAncestor在Window的整个Visual树中搜索一个元素? 如果是,那我该如何改进呢? 是 binding data error如果我们通过使用 Find Ancestor 找到一
我正在使用以下(简化的)代码在 ItemsControl 中的所有项目中显示一个元素,但第一个除外: NullToVisibility是一个简单的转换器,返回 Visibility.Hidden如果
我正在尝试创建一个包含 ListBox 的 View ,该 ListBox 的 ItemsSource 属性绑定(bind)到 ObservableCollection 并且其 ItemTemplat
我是 WPF 和 MVVM 模式的新手,所以我的绑定(bind)有一些问题。 在客户的详细信息 View 中,我想在组合框中列出一些状态。 在我的 ViewModel 中,客户处于根级别,状态列表也是
我正在尝试在项目控件 ItemContainerStyle 中使用转换器将 ItemsControl 中项目的属性转换为 X 值。要进行转换,我还需要对包含 ItemsControl 的父级 User
只是在这里做一个小测试。这两个文本框中只有第一个显示值“123”。为什么不是第二个? 最佳答案 用RelativeSource代替Source,像这样: 关于c# - WP
我试图在我的 Xaml 中绑定(bind)几个不同的属性: 你会注意到我在这里使用了两种不同的绑定(bind)技术。使用元素名称的工作,另一个不工作。这是后面的代码: public string D
我对 whn 在绑定(bind)时使用 {RelativeSource Self} 感到困惑。以下三个绑定(bind)在我看来是一样的,其中 MyText 是我的 View 模型中的一个属性。
对于以下 MultiBinding 表达式,如果多次更改 PropB,绑定(bind)引擎将搜索 DataGrid 祖先多少次? 如果 PropertyC(及其路径)
我已经构建了一个基于 WPF 的 Treeview 元素 -子项目 如果选择了子项目,我还想显示项目的属性。 我想我需要使用 RelativeSource 语句,但不太确定如何使用。
我创建了一个 UserControl 用于在我的应用程序中显示超链接。 UserControl 的标记如下:
我有一种情况需要使用描述的技术 here解析绑定(bind)引用 RelativeSource 的绑定(bind)。我正在使用自定义标记扩展来允许我将实际的 Binding 对象分配给 Depende
有人可以向我解释以下 XAML 行吗? DataContext="{Binding RelativeSource={RelativeSource Self}}" Here简单的使用示例。 如何用 C#
我有一个控件,在该控件内我有一个带有数据模板的资源: xmlns:vm="clr-namespace:CortexMonitoringTool.ViewModel" 我将 vm
我尝试使用 {RelativeSource PreviousData}在 ListBox.ItemTemplate它工作正常。 但是,当使用下面提供的特定代码时,绑定(bind)会在向上向下滚动几次和
我有以下 XAML,它完成了它应该做的所有事情,除了 FontSize 上的 MultiBinding 在检索用户时失败(当我在转换器中设置断点时,我看到了 DependencyProperty.Un
我是一名优秀的程序员,十分优秀!