开发者

How to bind an image into ListBoxItem in WPF?

开发者 https://www.devze.com 2023-02-13 21:53 出处:网络
I\'ve tried to bind my image into the listbox i\'ve created, yet it is just not working, can any1 help out with my problems so that i can actually bind the image into \"ListBoxItem\" as shown in the c

I've tried to bind my image into the listbox i've created, yet it is just not working, can any1 help out with my problems so that i can actually bind the image into "ListBoxItem" as shown in the code below.

Code behind:

    public object ImageSource
    {
        get
        {
            Image finalImage = new Image();
            BitmapImage logo = new BitmapImage();
            logo.BeginInit();
            logo.UriSource = new Uri(@"/images/food1.bmp", UriKind.Relative);
            logo.EndInit();
            finalImage.Source = logo;

            return logo;
        }
    }

XAML:

    <ListBox Grid.ColumnSpan="2">
            <ListBox.Resources>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Width" Value="100"/>
                    &l开发者_高级运维t;Setter Property="Height" Value="100"/>
                    <EventSetter Event="MouseLeftButtonDown" Handler="DragImage"/>
                </Style>
            </ListBox.Resources>
            <ListBoxItem>
                <Image Source="{Binding Path=ImageSource}" Width="197" Height="120" Margin="0,0,0,0"  />
            </ListBoxItem>
        </ListBox>


could be a problem with the imagesource. check if this solves your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消