问题标签 [element-binding]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1014 浏览

wpf - 访问 ComboBoxItem DisplayValue

我有一个包含对象列表的 ItemsSource 的组合框。因此 DisplayMemberPath 设置为对象的特定属性。当然这意味着正确的值显示在 ComboBoxItem 中。

我的问题是我希望能够获得由 XAML 中的 DisplayMemberPath 返回的“值”,以便我可以将其绑定到其他东西。即我想在 ComboBoxItem 上有一个“DisplayText”属性。

当然我没有这个,所以,有没有人知道一种方法来获取这个值,而无需遍历 ComboBoxItem 的模板来寻找 ContentHost?

如果您对我对此的具体使用感兴趣,我正在尝试对 ComboBox 的样式进行此操作:

Path=Content如果您只是将 ItemsSource 绑定到属性,当然可以正常工作,但是当它是具有 DisplayMemberPath 的对象时,内容将是该对象。

感谢您提供任何帮助或重新构建问题。

0 投票
1 回答
227 浏览

wpf - 如何将矩形的 RadiusX 绑定到矩形的 ActualHeight 并将其乘以 Expression Blend 4(或 VS)中的某个数字?

现在我正在“作弊”并使用以下内容:

x:Code在运行时完美运行并完成了我想要的。但我真的希望它通过执行以下操作立即改变Artboard

但是没有办法包括这个.5*(...)有没有另一种方法来完成这个?

0 投票
1 回答
1840 浏览

wpf - 如何将多个元素属性绑定到 wpf 中的一个元素?

使用上面的代码,我可以得到以下结果。

在此处输入图像描述

如果单击textBox1按钮将同时隐藏,我单击textBox2textBox3按钮将隐藏。

我需要的是,每当我点击textBox1texBox3时,按钮应该是隐藏的。我的意思是上面的线,

这可能吗 ?

0 投票
1 回答
232 浏览

xaml - 使用 ValueConverter 相对于其父级 ActualHeight 和另一个 ViewModel 属性定位 Line

我的 ViewModel 中有一个名为 的属性RelativeHeight,它是从 0 到 1 的双精度值。

在我的视图中,我有一条水平线,其宽度与其容器相同(通过Element Binding),但我希望它具有相对于容器大小的垂直位置。

例如,如果RelativeHeight0.3,并且容器ActualHeight200,那么Line.X1Line.X2将是60每个。

以下代码是我得到的,但不知道如何使用(或者即使我应该首先使用)一些IValueConverter,因为通常在调用该方法时我无法从视图中获取属性Convert......

0 投票
1 回答
106 浏览

wpf - 在不同的用户控件之间共享视图(不是视图模型)中的属性

我有一个显示类似于地理地图的视图,我UserControls在这个视图中有一些视图,每个视图都显示有关 DataContext 的相关信息,但每个视图都从不同的角度来看,可以这么说。

然后,我的目标是将鼠标悬停在一个 UserControl 上,突出显示每个 UserControl 中的一个功能,当然这个突出显示的视觉风格将特定于每个 UserControl。

例如,如果我在地图中有一条路径,并且在图表中绘制了它的海拔剖面,我想将鼠标悬停在海拔剖面上,在该图形上动态显示一条垂直线,同时一些标记将是动态的显示在地图中,反之亦然。

我可以通过在视图本身中使用一些数值来做到这一点,这将是每个用户控件中的双向数据绑定,但存在一些概念问题:

  • 经典数据绑定在 ViewModel 中预设了一个属性,但是“鼠标高亮”功能是特定于 View 的(它不代表对象状态),我绝对不希望将这样的属性添加到 ViewModel,这会污染它带有特定于视图的代码;
  • 创建 UserControl 时,它们的 DataContext 是 ViewModel 或其某些属性。需要将部分 UserControl 的 DataContext 更改为不同的对象似乎不是一个建议或简单的方法。
  • 我可以稍微破解一下并在具有折叠可见性的视图中创建一个Slider,并将 ElementBinding 与每个 UserControl 一起使用,但仍然如此,我将如何在视图和包含的 UserControl 之间进行 ElementBinding?

所以,主要问题是:

如何将视图中的单个属性(不是在 ViewModel 中!)绑定到给定视图中包含的许多用户控件?

如果一切都是一个单一的整体视图,那么使用 ElementBinding 对我来说是显而易见的选择,但是对于不同的类(一个视图和许多用户控件)我不知道如何进行 ElementBinding,或者即使它是正确的方法我想要的是。

0 投票
0 回答
113 浏览

firefox - FireFox 无法在拖动时获得鼠标位置

我在 Angular 中有以下代码

但是,无论如何,这只会返回相同的数字。如果我停止拖动并重新开始拖动,则它会返回pageY拖动开始的时间并保持在该数字上!为什么?

0 投票
1 回答
1752 浏览

c# - Binding ElementName from context menu can't find target

I am trying to bind to an element from a context menu inside a drop-down menu button (from http://shemesh.wordpress.com/2011/10/27/wpf-menubutton/). Even though outside the context menu the binding seems to work, the binding inside the context menu does not.

This is the XAML (very simplified):

The binding that does not work is the {Binding ElementName=pieChart}, which is funny because the command is being found. I couldn't seem to get a RelativeSource to work, but can someone help me with getting the binding correct?

0 投票
2 回答
32 浏览

wpf - Binding layout properties of different UserControls

I have the following layout for a screen displaying multi-channel information (similar to audio tracks):

  1. MultiChannelPlotterControl contains one HorizontalRuler instance at the bottom and a UniformGrid containing N SingleChannelPlotterControl instances;
  2. Each SingleChannelPlotterControl has one instance of VerticalRuler aligned to left;

enter image description here

Problems are:

  1. Each vertical ruler can have a different Width, but I would like them all to stretch to the largest width so that they could fit, but since they are on different controls, I cannot put them in the same container (another UniformGrid, for example. Now if I decide to put them together in a different container, they would not be part of the SingleChannelPlotterControl anymore;
  2. There is a rectangular region on the bottom left corner. That is supposed to have the same Width of the VerticalRuler(s), but it is still higher in the layout tree. It is currently empty, but I could put something there and bind its Width, for example;

So the question is:

How could I Layout/Element-Bind/Style these controls so that right edge of the Vertical Rulers keep aligned to each other (fitting the widest one) and with the left edge of the Horizontal Ruler?

EDIT: I guess I could create a "LeftPanelWidth" DependencyProperty on MultiChannelPlotterControl, and on its getter use some VisualTreeHelper wizardry to get ActualWidths for every VerticalRuler inside, but how would I choose the largest width and set the widths of the others?

0 投票
1 回答
51 浏览

c# - 如果两个涉及的对象都是在后面的代码中创建的,则元素绑定

在我的 WPF 项目中,我尝试在后面的代码中创建显示的对象。对于某些属性,我使用元素绑定,fe:

要在后面的代码中执行此操作,我使用以下代码:

其中“dummywidth1”是要使用的宽度的边框。

如果边框“dummywidth1”已经是 .xaml 文件的一部分,则此方法效果很好。如果我也在后面的代码中创建边框,则宽度不会应用于列。

并使用新的border.Name 进行绑定。

看来,元素绑定不适用于刚刚创建的 Border 对象。显示 WPF 时,在后面的代码中创建的边框具有所需的大小,但该大小不会传输到列。有什么方法可以实现与后面代码中创建的两个元素的元素绑定?

提前致谢,
弗兰克

0 投票
1 回答
388 浏览

c# - DataGridComboBoxColumn 上的元素绑定

是否可以将元素绑定与 DataGridComboBoxColumns 选定项一起使用?

我有一些对象 MyObject,它包含 ObservableCollection 类型的属性“ListOfSomeTypes”。SomeType 实现 INotifyPropertyChanged。

SomeType 列表应显示在 DataGrid 中。对于“ListOfSomeTypes”,我正在寻找执行以下操作的解决方案:DataGrid 有两列。一种是具有固定整数列表的 DataGridComboBoxColumn,例如 {0,1,2,3}。该列的 ItemsSource 是通过 Binding 设置的(属性“ListOfIndices”,它不是 MyObject 的一部分)。第二列应在所选索引位置(来自另一列)显示“ListOfSomeTypes”的内容。所以我想我可以使用 MultiConverter 来检查两者的值并选择正确的值进行显示。问题是,尽管组合框显示了我的索引列表的第一项,但从未设置过应该作为索引的值(null)。

由于索引只需要显示,我不想在我的 MyObject 类中有一个“SelectedIndex”属性。是否可以通过元素绑定访问组合框的选定值?需要使用哪个属性(因为 SelectedValueBinding 似乎是错误的)?或者,还有更好的方法?

这是我的代码:

转换器

谢谢你的帮助!