How to display an image in a template where the source is a TemplateBinding in a WPF design view?

I have the following template ImageTextRadioButton

for a Button RadioButton with text and image in it:

<ControlTemplate TargetType="RadioButton" x:Key="ImageTextRadioButton">
  <Border  Background="{TemplateBinding Background}" BorderBrush="Black" CornerRadius="8" BorderThickness="2">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width=".5*" />
        <ColumnDefinition Width="1*" />
      </Grid.ColumnDefinitions>
        <Image x:Name="ButtonImage" Grid.Column="0" Source="{TemplateBinding Content}" Stretch="None" />
        <TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{TemplateBinding Content}" />
    </Grid>
  </Border>
</ControlTemplate>

      

(Note: the content in TemplateBindings is just a string containing the path + filename of the image).

This works as expected in launch mode, but in design mode it does not display an image. The text block displays the correct text and if I replace Image.Source

with a hardcoded value the image is displayed correctly as well. But the image just won't display correctly in source design mode TemplateBinding

.

+3


source to share


1 answer


Argh, I had .png files as embedded resources, so the converter had to report the filename as "/MyProject;component/images/" + value + ".png"

instead "../images/" + value + ".png"

. Once I made this change in the converter everything worked.



+3


source







All Articles