Anchor position to ActualHeight

I want to bind the position of lists to their height in XAML. So its bottom left corner will always be at 0.0 of the canvas. I am using elementBinding to force ActualHeight

and the converter to invert a property. But the height sent to the transformer is 0.

How can I solve this problem or am I not mistaken?

<Canvas x:Name="DisplaySurface">
    <ListBox x:Name="MenuList" Visibility="Visible"  
             Canvas.Top="{Binding ElementName=MenuList, Path=ActualHeight, 
             Converter={StaticResource LamdaConv}, ConverterParameter='val=>-val'}">

         <ListBoxItem Content="item 1" />
         <ListBoxItem Content="item 2" />
         <ListBoxItem Content="item 3" />
         <ListBoxItem Content="item 4" />
         <ListBoxItem Content="item 5" />
         <ListBoxItem Content="item 6" />
     </ListBox>
</Canvas>

      

+2


a source to share


2 answers


Try binding {Binding ActualHeight, RelativeSource={RelativeSource Self},Converter={StaticResource LamdaConv}, ConverterParameter='val=>-val'}



+1


a source


It seems to me that you are using the wrong control to work. A Grid

can handle this effortlessly: -

 <Grid>

    <Canvas x:Name="DisplaySurface">
    </Canvas>
    <ListBox HorizontalAlignment="Left" VerticalAlignment="Bottom" ...>
       <!-- items --->
    </ListBox>
</Grid> 

      



Now ListBox

always appears in the lower left corner. Not only that, but if the total available height is less than the height of all the content in the list, it will be limited by the available height and show a scroll bar. Something that your code would otherwise have to jump over hoops.

+1


a source







All Articles