pdf to image
pdf to image

Reputation: 369

wpf: bind border width with image width

I'm adding a functionality to my program which views image thumbnails to listview.

What i want is bind the width of border to my image but i can't make it work

here is my code

        <Border x:Name="imgbrdr" BorderBrush="Black" BorderThickness="1" Margin="5,5,5,5">
     <ListView Name="Thumbnails" SelectionChanged="Thumbnails_SelectionChanged" >
          <ListView.ItemTemplate>
               <DataTemplate>
                    <Image Source="{Binding Source}" Height="{Binding ElementName=imgbrdr}" RenderOptions.BitmapScalingMode="HighQuality"/>
               </DataTemplate>
          </ListView.ItemTemplate>
 </ListView>
</Border>

Upvotes: 0

Views: 641

Answers (2)

Clemens
Clemens

Reputation: 128147

You don't need that Binding at all.

To make the images the same width as the ListView, you only need to disable horizontal scrolling. You can then also set a Margin on the Image controls. With a ListView width of e.g. 200 and a Margin of 10, the images would be 180 wide.

<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding Source}" Margin="10"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListView>

Note also that you could as well use a ListBox, which is the base class of ListView.

Upvotes: 1

d.moncada
d.moncada

Reputation: 17402

You forgot to add the property path of the Border.

<Image Source="{Binding Source}" Height="{Binding ElementName=imgbrdr, Path=ActualHeight}" RenderOptions.BitmapScalingMode="HighQuality"/>

Upvotes: 3

Related Questions