Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

DisplayMemberPath for WPF CustumControl

$
0
0

Hi, 

I'm writing CustumControl inherited from UserControl.

So, I have a ListBox that contain Image as ItemTemplate. I want to do a DisplayMemberPath property same as the ListBox or ComboBox.

<UserControl ....>

<ListBox ItemsSource="{Binding ItemImageSource,ElementName=_this}" SelectedItem="{Binding SelectedImage,ElementName=_this,Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex,ElementName=_this,Mode=TwoWay}"><ListBox.Style><Style TargetType="{x:Type ListBox}"><Setter Property="ItemTemplate"><Setter.Value><DataTemplate><Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="3" Margin="6"><Image Source="{Binding Path=UriSource}" Stretch="Fill" Width="{Binding ImageWidth,ElementName=_this}" Height="auto" Margin="6"/><!--{Binding Path=UriSource}--></Border></DataTemplate></Setter.Value></Setter></Style></ListBox.Style></ListBox>

</UserControl>


As in the sample, when i bind a List<BitmapImage>. It works (Display Images).

But when I bind to a list of object (custom class) that contain TheImage (BitmapImage). I'll must to change the source of my control (By Replacing {Binding Path=UriSource} by{Binding Path=TheImage.UriSource}).

So how can I do a DisplayMemberPath for my CustumControl?

Thank you for reading. If there are any detail that may help you to understand me, I'm waiting for your reply.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>