0

I am trying to overlay an image on my BoardSquares but when trying to specify a Source on my Image it says The member "Source" is not recognized or is not accessible. Any idea what I could be doing wrong? P.S I omitted the DataTemplate Triggers but they're there.

<ItemsControl ItemsSource="{Binding BoardGUI.BoardSquares}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Rows="10" Columns="10"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button x:Name="Square" Command="{Binding DataContext.BoardGUI.SquareClickCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}"> <Button.Template> <ControlTemplate TargetType="Button"> <Grid Background="{TemplateBinding Background}"> <Image Source="{TemplateBinding Source}"/> </Grid> </ControlTemplate> </Button.Template> </Button> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 
1
  • Button class doesn't have Source property, {TemplateBinding Source} won't work. What is that Source? Commented Dec 6, 2016 at 11:20

1 Answer 1

1

Any idea what I could be doing wrong?

{TemplateBinding Source} tries to bind to a Source property of the templated parent which is the Button in this case and a Button has no Source property.

If the type of objects in the BoardSquares source collection has a Source property you should use the {Binding} markup extension to bind to this:

<Button.Template> <ControlTemplate TargetType="Button"> <Grid Background="{TemplateBinding Background}"> <Image Source="{Binding Source}"/> </Grid> </ControlTemplate> </Button.Template> 

If you simply want to set the Source property of the Image to a non-dynamic image source, you could just specify a Uri to this image:

<Image Source="Images/pic.png"/> 
Sign up to request clarification or add additional context in comments.

1 Comment

I much prefer answers that Explain the problem as well as provide the answer +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.