2016-12-06 27 views
0

BoardSquaresにイメージをオーバーレイしようとしていますが、ImageSourceを指定しようとすると、The member "Source" is not recognized or is not accessibleと表示されます。私は間違って何をすることができますか? P.S私はDataTemplateトリガを省略しましたが、そこにあります。私が間違っていることができるものWPFイメージソースが認識されないかアクセスできない

<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> 
+0

ボタンクラスにはソースプロパティがなく、{TemplateBinding Source}は動作しません。その「源」とは何ですか? – ASh

答えて

1

任意のアイデア?

{TemplateBinding Source}は、テンプレートの親のSourceプロパティ(この場合はButton)にバインドしようとし、ButtonにはSourceプロパティはありません。あなたは、単にSourceプロパティを設定する場合

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

:BoardSquaresのソースコレクション内のオブジェクトの型がSourceプロパティを持っている場合は、これにバインドする{バインディング}マークアップ拡張機能を使用する必要があります

<Image Source="Images/pic.png"/> 
+0

私は問題を説明するだけでなく、答えを提供することを好む+1 – MikeT

関連する問題