0
我已经在我的资源文件中定义的样式像下面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 2010-12-18 09:10:41
我想在另一个资源文件中定义列表框的样式,并在我的page.xaml中指定该样式。什么是正确的方式? – user20358 2010-12-18 10:13:07