以下のようにリソースファイルにスタイルを定義しました
<Style x:Name="ListBoxStyle" TargetType="ListBox" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name,Mode=TwoWay}"
Margin="5"
Foreground="Red">
</TextBlock>
<TextBlock Text="{Binding Age,Mode=TwoWay}"
Margin="5">
</TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
ここのデータテンプレートに何を入れるか迷っています
<ListBox x:Name="MyList" ItemsSource="{Binding }">
<ListBox.ItemTemplate>
<DataTemplate>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
使ってみた
<ContentPresenter Style="{StaticResource ListBoxStyle}"></ContentPresenter>
そしてさえ
<ContentControl Style="{StaticResource ListBoxStyle}"></ContentControl>`
しかし、このエラーが発生しました
プロパティ 'System.Windows.FrameworkElement.Style' への割り当てに失敗しました。
DataTemplate
カスタム スタイルを提供したい場合、タグの間に何を入れればよいですか?