Xaml 使用静态内容设置列表框的样式

Xaml 使用静态内容设置列表框的样式,xaml,windows-phone-7,listbox,styling,Xaml,Windows Phone 7,Listbox,Styling,我在列表框控件中有一组我想要的静态内容 <ListBox> <ListBox.Items> <ListBoxItem> <Image /> <TextBlock Text="One" /> </ListBoxItem> <ListBoxItem> <Image />

我在
列表框
控件中有一组我想要的静态内容

<ListBox>
    <ListBox.Items>
        <ListBoxItem>
            <Image />
            <TextBlock Text="One" />
        </ListBoxItem>
        <ListBoxItem>
            <Image />
            <TextBlock Text="Two" />
        </ListBoxItem>
        <ListBoxItem>
            <Image />
            <TextBlock Text="Three" />
        </ListBoxItem>
    </ListBox.Items>
</ListBox>


我该如何设计这个?我知道我可以分别设置每个
ListBoxItem
的样式,并且我知道如何在数据绑定时设置样式,但是在使用这样的静态内容时如何设置ListBoxItem模板的样式?

您可以将项目定义为低级对象并使用数据模板,这可能与样式不同,但属性也只能设置一次:

<ListBox xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <ListBox.Items>
        <sys:String>one</sys:String>
        <sys:String>two</sys:String>
        <sys:String>three</sys:String>
    </ListBox.Items>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <!-- "Style" this at will -->
            <StackPanel>
                <Image />
                <TextBlock Text="{Binding}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

我在WP7设备上做这个,显然这种格式不起作用
x:Type
不是架构的一部分。
Style
节点上没有
Style.Resources
。可能手机的模式声明不同,或者手机不支持这种方式。对,您可能不应该用WPF标记WP7问题,因为它与Silverlight不完全相同,它代表WPF的一个子集,而这些在那里是不可能的,这很遗憾
x:Type
不是必需的。顺便说一句,您可以在这种情况下键入名称,因为编译器知道字符串需要转换为类型,但我不知道如何处理缺少
样式的问题。参考资料
,抱歉。我将更改标记。我觉得样式不会有什么不同。@Josh:我只是又看了一遍,并添加了另一种方法,希望它能起作用(我只能用普通的Silverlight进行测试)
<ListBox>
    <ListBox.Resources>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Resources>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Width" Value="100"/>
                </Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="Foreground" Value="Blue"/>
                </Style>
            </Style.Resources>
        </Style>
    </ListBox.Resources>
    <!-- Items here -->
</ListBox>