English 中文(简体)
WPF 数据捆绑——从温度到每秒到每秒
原标题:WPF Data Binding - Bind to UI Control from a Template

我的一节有一个模板。 我想把该模板中的一种数值的神话与我的主要XAML部分的控制关系。

能否做到这一点? 宣 言 透镜只显示装束清单中的模板。

例如,这是我想要做的工作:

<Windows.Resources>
... My template stuff
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="20" />
      <ColumnDefinition Width="50" />
      <ColumnDefinition Width="{Binding ElementName=SecondColumn, Path=Width}"/>
      <ColumnDefinition Width="30" />
   </Grid.ColumnDefinitions>
... More template stuff
</Windwos.Resources>

<Grid Name="MainGrid">
   <Grid.ColumnDefinitions>
      <ColumnDefinition Name="FirstColumn" Width=".25*" />
      <ColumnDefinition Name="SecondColumn" Width=".5*" />
      <ColumnDefinition Name="ThirdColumn"  Width=".25*" />
   </Grid.ColumnDefinitions>
... Rest of my XAML
最佳回答

一旦在座标内,你会重新区分与其他元素(有良好理由)的分离。 在这种情况下(假设该模板在“MainGrid”的某个地方使用),它想像你能够使用一种相对的Source FindAncestor Bled来寻找父母Gred(需要确保视力T里的格里德人获得正确的血压水平——这里的法典就是2)。 这条道路将排在第1栏。 Width。 铭记这取决于你是否维持你使用该模板的要素的结构,因此它非常脆弱。 还有一个使用共享组的备用方法,可以将Grid Rows或Columns连接到不同级别,但只与自动和固定的子板尺寸合作。 这一约束性方法具有固定规模和大小。

加入:

Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=2}, Path=ColumnDefinitions[1].Width}"
问题回答

您是否意味着您的栏目总是相同的宽度,或者说,首先,其宽度相同? 如果是的话,为什么不从两栏界定风格并加以使用?





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签