私は途方に暮れていますSilverlightのリストボックスのカスタムスタイル
<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
タグの間に何を挿入しますか?
あなたは何をしたいですか? 'ListBox'のスタイルを定義していて、それを' ContentPresenter'と 'ContentControl'に適用しようとしています。それはあってない。 – decyclone
リストボックスのスタイルを別のリソースファイルに定義し、私のpage.xamlでそのスタイルを参照したいだけです。正しい方法は何ですか? – user20358