绑定到wpf中父元素的属性

发布于 2024-08-25 00:24:22 字数 2570 浏览 16 评论 0原文

'我想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

也只是曾经 2024-09-01 00:24:22

我不知道你的 RadGridView 在这里。但我要尝试的第一件事是使用 RelativeSource 与 FindAncestor 绑定沿着可视化树向上移动,直到找到 GridViewHeaderRow 并绑定到其 Height 属性。

 ... Height="{Binding Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type GridViewHeaderRow }}}" ...

您可能必须沿着树向上走才能找到 RadGridView,然后沿着树走回标题行。

 ... Height="{Binding HeaderRow.Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type RadGridView }}}" ...

 ... Height="{Binding Rows[0].Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type 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.

 ... Height="{Binding Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type GridViewHeaderRow }}}" ...

You may have to walk up the tree to find the RadGridView and then walk back down it to the header row.

 ... Height="{Binding HeaderRow.Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type RadGridView }}}" ...

or

 ... Height="{Binding Rows[0].Height, 
              RelativeSource={RelativeSource Mode=FindAncestor, 
                                 AncestorType={x:Type RadGridView }}}" ...

Depends on the implementation of RadGridView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文