リスト ボックスのイメージは表示されますが、ボタンのイメージは表示されません。何か案は?DataTemplate を使用して画像をボタンにバインドするにはどうすればよいですか?
namespace wpftest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string URL1 = "example.com/test.jpg";
public MainWindow()
{
InitializeComponent();
MyObj list = new MyObj(URL1);
List<MyObj> _list = new List<MyObj>()
{
new MyObj{ url1 = "example.com/test.jpg"},
new MyObj{ url1 = "example.com/test.jpg"},
new MyObj{ url1 = "example.com/test.jpg"}
};
button1.DataContext = new MyObj { url1 = "example.com/test.jpg" };
listBox1.DataContext = new CollectionViewSource { Source = _list };
}
}
}
/////////////////////////////////////////////// ///////////////////////////////////
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Res="clr-namespace:wpftest.Properties"
>
<DataTemplate x:Key="myTemplate">
<StackPanel Orientation="Horizontal">
<Image Height="307" Name="image1" Stretch="None" Width="300" Source="{Binding url1}"/>
<StackPanel>
<TextBlock
Text="{x:Static Res:Resources.Title}"/>
<TextBlock Text="URL"/>
</StackPanel>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="customImageTileButton">
<StackPanel Orientation="Horizontal">
<Image Height="307" Name="image1" Stretch="None" Width="300" Source="{Binding url1}"/>
<TextBlock Name="customTitle" Text="Title"/>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
/////////////////////////////////////////////// ///
<Window x:Class="wpftest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="720" Width="1280"
xmlns:Res="clr-namespace:wpftest.Properties" DataContext="{Binding}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<StackPanel Height="457" HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="1258" >
<ListBox Height="452" Name="listBox1" Width="1253"
ItemTemplate="{StaticResource myTemplate}"
ItemsSource="{Binding}">
</ListBox>
</StackPanel>
<Button Content="Button"
ContentTemplate="{StaticResource customImageTileButton}"
HorizontalAlignment="Left"
Margin="84,492,0,0"
Name="button1"
VerticalAlignment="Top"
/>
</Grid>