1

I am working on a C# image where I receive an XML message where one of the elements is a base 64 encoded image.

I am using the dynamic data binding within the WPF element and I want to add an image to the list item.

Below is the WPF that I am currently using

<ListView Height="397" HorizontalAlignment="Left" Margin="491,29,0,0" Name="lstCallLogInformation" 
                 VerticalAlignment="Top" Width="320">
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" VerticalAlignment="Bottom" />
                                                </StackPanel>
                                            </Expander.Header>
                                            <Expander.Content>
                                                <ItemsPresenter />
                                            </Expander.Content>
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <DockPanel>
                        <StackPanel Orientation="Vertical">
                            <TextBlock Text="{Binding contactNameOrPhoneNumber}" FontWeight="Bold" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding dateString}" HorizontalAlignment="Left" />
                                <TextBlock Text="{Binding callDuration}" HorizontalAlignment="Right" />
                            </StackPanel>
                        </StackPanel>
                    </DockPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

So basically within a StackPanel I want to have something like:

<Image Source="{Binding myBase64EncodedProperty}" />

I can't find anything about how this could be possible.

halfer
  • 19,824
  • 17
  • 99
  • 186
Boardy
  • 35,417
  • 104
  • 256
  • 447

1 Answers1

1

What you'll need to do is convert your Base64 string into a BitmapImage. I'm not going to copy/paste or repeat the answer, but look at this answer to the exact question you are trying to solve: https://stackoverflow.com/a/593489/347172

Community
  • 1
  • 1
myermian
  • 31,823
  • 24
  • 123
  • 215