问题描述
我还看到了其他一些Silverlight'vs'问题,但在此特定的比赛中找不到任何问题。
I've seen a few other Silverlight 'vs' questions around, but couldn't find any for this particular match-up.
我正在尝试定义绑定到 ListBox
的对象的显示方式。我已经定义了 DataTemplate
,但是我真的不确定应该在哪里结束, ItemContainerStyle
应该开始。
I'm trying to define the way in which my objects bound to a ListBox
will display. I've defined a DataTemplate
, but I'm really not sure where this should end and the ItemContainerStyle
should begin.
问题1:
是 ItemContainerStyle
的唯一包装 DataTemplate
以便可以将通用项目样式应用于不同的数据布局?
Question 1:Is the ItemContainerStyle
just a wrapper for the DataTemplate
so that a common item style can be applied to different data layouts?
问题1a:如果是这样,如果不需要通用的商品样式,则 ItemContainerStyle
甚至可以在 DataTemplate
中定义所有布局和样式吗?
Question 1a: If so, in the event that a common item style isn't required, is the ItemContainerStyle
even necessary or can all the layout and styling be defined in the DataTemplate
?
问题1b:,如果不是,
ListBox
当前如下:
<ListBox Margin="40,118,41,61" ItemTemplate="{StaticResource TaskDataTemplate}"/>
我的 DataTemplate
的XAML就像这样:
The XAML for my DataTemplate
is like this:
<DataTemplate x:Key="TaskDataTemplate">
<Grid d:DesignHeight="95" Height="150">
<StackPanel Margin="11,8,-10,68" Orientation="Horizontal" d:LayoutOverrides="Width">
<TextBlock x:Name="TaskLabel" Margin="0,0,0,8" Style="{StaticResource TitleTextSmall}" TextWrapping="Wrap" Text="Task" VerticalAlignment="Stretch" d:LayoutOverrides="Height"/>
<TextBlock x:Name="TaskID" HorizontalAlignment="Right" Margin="10,0,0,0" Style="{StaticResource TitleTextSmall}" TextWrapping="Wrap" Text="TaskID" VerticalAlignment="Stretch" d:LayoutOverrides="Height"/>
<TextBlock x:Name="ChangeList" Style="{StaticResource NormalText}" TextWrapping="Wrap" Text="Changes..." Margin="30,2,0,0"/>
</StackPanel>
<ComboBox x:Name="TaskType" Style="{StaticResource TaskComboBox}" Height="29" VerticalAlignment="Top" Margin="131,30,16,0" d:LayoutOverrides="VerticalAlignment"/>
<TextBlock x:Name="TaskTypeLabel" Margin="12,39,0,0" Style="{StaticResource NormalTextBold}" TextWrapping="Wrap" Text="Variation Reason" VerticalAlignment="Top" HorizontalAlignment="Left" Height="21"/>
<TextBox x:Name="TaskDescription" Margin="12,70,15,11" TextWrapping="Wrap" Text="Enter description..." Style="{StaticResource TaskTextBox}" d:LayoutOverrides="VerticalAlignment"/>
</Grid>
</DataTemplate>
谢谢。
推荐答案
答案1:是
答案1a:据我所知,您可以在ItemTemplate中进行所有样式设置,但ItemContainerStyle具有可控制的VisualStates
Answer 1a: as far as I can tell you can do all your styling in the ItemTemplate but the ItemContainerStyle has VisualStates which control the Opacity on mouse over/disabled/selected etc.
如果要更改这些不透明度状态更改,或者想要除矩形以外的任何Container形状,例如a例如三角形,那么您将不得不覆盖默认的ItemContainerStyle。
If you want to change those opacity state changes, or if you want any Container shape other than a rectangle, like a triangle for example, then you'll have to override the default ItemContainerStyle.
这篇关于DataTemplate与ItemContainerStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!