数据模板与 ItemContainerStyle
我见过一些其他 Silverlight 'vs' 问题,但找不到任何针对此特定匹配的问题。
我正在尝试定义绑定到 ListBox
的对象的显示方式。我已经定义了一个 DataTemplate
,但我真的不确定它应该在哪里结束以及 ItemContainerStyle
应该开始。
问题 1: ItemContainerStyle
是否只是 DataTemplate
的包装器,以便可以将通用项目样式应用于不同的数据布局?
问题 1a:如果是这样,在不需要通用项目样式的情况下,ItemContainerStyle
是否必要,或者所有布局和样式都可以在 ItemContainerStyle
中定义吗?代码>数据模板?
问题 1b:如果不是,那它是什么?
ListBox
目前是这样的:
<ListBox Margin="40,118,41,61" ItemTemplate="{StaticResource TaskDataTemplate}"/>
我的 DataTemplate
的 XAML 是这样的:
<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>
谢谢。
I've seen a few other Silverlight 'vs' questions around, but couldn't find any for this particular match-up.
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.
Question 1:
Is the ItemContainerStyle
just a wrapper for the DataTemplate
so that a common item style can be applied to different data layouts?
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
?
Question 1b: If not, so what is it?
The ListBox
is currently like this:
<ListBox Margin="40,118,41,61" ItemTemplate="{StaticResource TaskDataTemplate}"/>
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>
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案 1:是
答案 1a:据我所知,您可以在 ItemTemplate 中完成所有样式设置,但 ItemContainerStyle 具有 VisualStates,它控制鼠标悬停/禁用/选择等时的不透明度。
如果您想更改这些不透明度状态更改,或者,如果您想要矩形以外的任何容器形状(例如三角形),那么您必须覆盖默认的 ItemContainerStyle。
Answer 1: yes
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.
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.