Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Border DesiredHeight

The following Microsoft example code contains the following:

<Grid>
...     
  <Border Name="Content" ... >
...     
  </Border>
</Grid>
<ControlTemplate.Triggers>
  <Trigger Property="IsExpanded" Value="True">
     <Setter TargetName="ContentRow" Property="Height"
             Value="{Binding ElementName=Content,Path=DesiredHeight}" />
  </Trigger>
...
</ControlTemplate.Triggers>

When run, however, this code generates the following databinding error:

System.Windows.Data Error: 39 : BindingExpression path error: 'DesiredHeight' property not found on 'object' ''Border' (Name='Content')'. BindingExpression:Path=DesiredHeight; DataItem='Border' (Name='Content'); target element is 'RowDefinition' (HashCode=2034711); target property is 'Height' (type 'GridLength')

Despite this error, the code works correctly. I have looked through the documentation and DesiredHeight does not appear to be a member of Border. Can anyone explain where DesiredHeight is coming from? Also, is there any way to resolve/suppress this error so my program output is clean?

like image 854
Joseph Sturtevant Avatar asked May 19 '09 16:05

Joseph Sturtevant


2 Answers

You can see that property in the code part of your application

Edit:

Border content = new Border();
int desiredHeight = content.DesiredSize.Height;
int desiredWidth = content.DesiredSize.Width;

To solve the problem try binding it to the Height attribute, since DesiredHeight doesn't seem to be available in the XAML markup of the Border control.

like image 167
Carlo Avatar answered Sep 25 '22 03:09

Carlo


Had the same issue. Was using a custom Expander in a custom ComboBox. None of the above worked for me, binding to Height broke the functionality of the Expander, using a StackPanel also broke the displaying of the items in each group. I found:

<Setter TargetName="ContentRow" Property="Height" Value="Auto"/>
like image 42
Andy Powell Avatar answered Sep 25 '22 03:09

Andy Powell