绑定到wpf中父元素的属性
'我想将 RichTextBox 的 Height 属性绑定到 GridView 行的 Height 属性。我怎样才能做到这一点?我不知道如何获取行的高度,因为我无法访问我想做的 xaml 中的行。
Ancestor 类型应该是 GridViewHeaderRow ,但我不知道它的级别...
编辑:
<my:RadGridView Height="524" RowHeight="300" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn DataMemberBinding="{Binding SchoolclassName}" Header="Schoolclass" Width="0.1*" />
<my:GridViewDataColumn DataMemberBinding="{Binding SubjectName}" Header="Subject" Width="0.1*" />
<my:GridViewDataColumn Width="0.3*" Header="Homework">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=dataGrid1,Path=RowHeight}" >
<FlowDocument>
<Paragraph>
<Run Text="{Binding Homework}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
<my:RadGridView Height="524" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn Name="ContentColumn" Width="0.3*" Header="Content">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=MyRowNameToBindTo,Path=Height}">
<FlowDocument>
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
...
'I want to bind the Height property of the RichTextBox to the Height Property of the GridView`s Row. How can I do that? I do not know how to get the Row's Height as I can not access the Row in xaml what I would like to do.
The Ancestor type should be GridViewHeaderRow , but I do not know its level...
EDIT:
<my:RadGridView Height="524" RowHeight="300" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn DataMemberBinding="{Binding SchoolclassName}" Header="Schoolclass" Width="0.1*" />
<my:GridViewDataColumn DataMemberBinding="{Binding SubjectName}" Header="Subject" Width="0.1*" />
<my:GridViewDataColumn Width="0.3*" Header="Homework">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=dataGrid1,Path=RowHeight}" >
<FlowDocument>
<Paragraph>
<Run Text="{Binding Homework}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
<my:RadGridView Height="524" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn Name="ContentColumn" Width="0.3*" Header="Content">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=MyRowNameToBindTo,Path=Height}">
<FlowDocument>
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你的 RadGridView 在这里。但我要尝试的第一件事是使用 RelativeSource 与 FindAncestor 绑定沿着可视化树向上移动,直到找到 GridViewHeaderRow 并绑定到其 Height 属性。
您可能必须沿着树向上走才能找到 RadGridView,然后沿着树走回标题行。
或
取决于 RadGridView 的实现。
I don't know about your RadGridView here. But the first thing I'd try is using a RelativeSource Binding with FindAncestor to walk up the visual tree until a GridViewHeaderRow is found and bind to its Height property.
You may have to walk up the tree to find the RadGridView and then walk back down it to the header row.
or
Depends on the implementation of RadGridView.