0

I have a grid that I want a popup to show in a constant relation to it regardless of the size of both the popup and the grid. I use a converter for it here is the code

 < Grid Name=YParamTextBlock>
       <TextBlock HorizontalAlignment="Center"/>
       <Popup PlacementTarget="{Binding ElementName=YParamTextBlock}} Placement="Center">
             <Popup.VerticalOffSet>
                  <MultiBinding Mode="OneWay" Converter="{StaticResource OffsetConverter} NotifyOnTargetChanged="True">
                         <Binding Mode="OneWay" ElementName="YParamTextBlock" Path="ActualHeight" NotifyOnTargetUpdated="True"/>
                         <Binding Mode="OneWay" RelativeSource={RelativeSource Self} Path="ActualHeight" NotifyOnTargetChanged="True"/>
                    </MultiBinding>
               </Popup.VerticalOffset>
        </Popup>
  <Grid>

The problem is that the actual height is 0.0 for the two controls when they are first created, so I added the NotifyOnTargetChanged in order to fix it. Now, for some reason the NotifyOnTargetChanged fixed the rebinding for the Grid's ActualHeight, but the Popup is still 0.0. Is there anyway to notify the popup actual height has changed? Or any other solution for this issue?

gilmishal
  • 1,884
  • 1
  • 22
  • 37
  • Sorry for the bad code part, i wrote this on my smartphone. If someone would edit my question to show the code correctlyI would be grateful.. – gilmishal Jan 22 '14 at 09:51

2 Answers2

0

Actual Height and Width are read-only you cannot bind directly, you can use the solution explained by Kent Boogaart in this Answer

Community
  • 1
  • 1
Mujahid Daud Khan
  • 1,983
  • 1
  • 14
  • 23
  • I did, for some reason, it looks like this... I used my smartphone to write the post, and it formated this way... I need someone with a computer to edit it.. – gilmishal Jan 22 '14 at 10:19
0

Why the multibinding? VerticalOffset is a double so you just need one binding value.

I don't know what your Converter does, but assuming you want it to take the ActualHeight property of your YParamTextBlock grid and then return a double corresponding to the VerticalOffset you want to give to your popup then the following is probably easier to follow:

<Grid x:Name="YParamTextBlock">
       <TextBlock HorizontalAlignment="Center"/>
       <Popup PlacementTarget="{Binding ElementName=YParamTextBlock}} 
              Placement="Center"
              VerticalOffset="{Binding ActualHeight, ElementName=YParamTextBlock, 
                               Converter={StaticResource OffsetConverter}}"/>

<Grid>
Mashton
  • 6,037
  • 2
  • 25
  • 35