views:

745

answers:

1

Hello all, '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>

...

+2  A: 

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.

Travis Heseman
I have changed/EDIT the init Question with updated code:why do I get errors on this: <RichTextBox Height="{Binding ElementName=dataGrid1,Path=RowHeight}" >I forgot, that RadGridView has a RowHeight property I can bind to via ElementName...
msfanboy
why do I get this error?System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=dataGrid1'. BindingExpression:Path=RowHeight; DataItem=null; target element is 'RichTextBox' (Name=''); target property is 'Height' (type 'Double')
msfanboy
ok one more reason to hate teleriks crappy datagrid too.public double RowHeight {get; set;}its no dependency property... :S
msfanboy
It's possible that your RadGridView does not have a NameScope and thus is suffering from the same issue as discussed here - http://joshsmithonwpf.wordpress.com/2008/07/22/enable-elementname-bindings-with-elementspy/.
Travis Heseman
hehe funny I found the same thread yesterday. I do not want to leak reflection into my app ;-) Well it wouldnt be my job to fix that rather its telerik job to make the RowHeight a dependency property. This I will suggest to them going to be a customer sometimes. If they suck at doing this I will open a blog and do some rants XD
msfanboy
now hold yourself:using this in native DataGrid<RichtTextBox Height="{Binding ElementName=customerDG,Path=RowHeight}" />works! :P seems this time MS did their homework although this is exceptional XD
msfanboy