Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 927967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:56:05+00:00 2026-05-15T19:56:05+00:00

How can I DataBind my Image control to automatically get the player.PlayerImage updates? As

  • 0

How can I DataBind my Image control to automatically get the player.PlayerImage updates? As you can see from my code, I have tried to setup databinding, however it’s not working.

Below is my current setup:

I have a CLR class called CDGPlayer that implements INotifyPropertyChanged.

The CDGPlayer class has a property called PlayerImage

private Image playerImage;
public Image PlayerImage
{
    get { return playerImage; }
    set
    {
        if (value != playerImage)
        {
            playerImage = value;
            NotifyPropertyChanged("PlayerImage");
        }
    }
}

I have a WPF client that I would like to use the CDGPlayer.

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:CDG="clr-namespace:GoldenKaraokeLib.CDG;assembly=GoldenKaraokeLib" 
    xmlns:local="clr-namespace:GoldenKaraokePlayerWPF" 
    x:Class="GoldenKaraokePlayerWPF.Window1"
    Title="Window1" Height="300" Width="654"
        x:Name="CDGPlayerHost" Loaded="CdgPlayerHostLoaded" Background="#FFCD6F6F">
    <Window.Resources>
        <local:CdgImageConverter x:Key="CDGImageConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.DataContext>
            <CDG:CDGPlayer x:Name="player"/>
        </Grid.DataContext>
        <Border BorderBrush="Black" BorderThickness="5">
            <Image x:Name="CDGImage" Source="{Binding PlayerImage, Converter={StaticResource CDGImageConverter}, UpdateSourceTrigger=PropertyChanged}"/>
        </Border>
    </Grid>
</Window>

in the Window1.cs file I have a Loaded event that calls the CDGPlayer class instance and invokes the Play method. This method generates a new System.Drawing.Image and stores it in PlayerImage.

I know the CDGImage Source property can not accept an System.Drawing.Image so I’ve attempted to write a crude converter. However, this is only called once on window load.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    try
    {
        MemoryStream ms = new MemoryStream();
        Image bitmap = value as Image;
        BitmapImage bi = new BitmapImage();

        if (bitmap != null)
        {
            bitmap.Save(ms, ImageFormat.Bmp);

            bi.BeginInit();
            bi.StreamSource = ms;
            bi.EndInit();
        }

        return bi;
    }
    catch
    {
        return new BitmapImage();
    }
}

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:56:06+00:00Added an answer on May 15, 2026 at 7:56 pm

    Your binding appears to be correct when I try it. It looks like your converter has a bug, though. You don’t rewind the stream, so BitmapImage will try to read starting from the end instead of starting from the beginning. Add a call to Stream.Seek:

    if (bitmap != null)
    {
        bitmap.Save(ms, ImageFormat.Bmp);
        ms.Seek(0, SeekOrigin.Begin); // Set position back to the start of the stream
        bi.BeginInit();
        bi.StreamSource = ms;
        bi.EndInit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.