首页 新闻 会员 周边

WPF ListBox样式

0
悬赏园豆:10 [已解决问题] 解决于 2013-12-01 23:17

请问我这段代码有啥问题:

<ListBox x:Name="lstUserInfo" VerticalAlignment="Center" HorizontalAlignment="Center" Height="50" Width="120">
            <ListBox.Items>
                <ListBoxItem>
                    <ListBoxItem.Template>
                        <ControlTemplate>
                            <Border Background="Blue">
                                <Border.Style>
                                    <Style>
                                        <Setter Property="Border.Background" Value="Blue"/>
                                    </Style>
                                </Border.Style>
                                <Border.Triggers>                                    
                                    <Trigger Property="Border.IsMouseOver" Value="true">
                                        <Setter Property="Border.Background" Value="Red"/>     
                                    </Trigger>
                                </Border.Triggers>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding UserName}"/>
                                    <TextBlock Text="{Binding Age}"/>
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </ListBoxItem.Template>
                </ListBoxItem>
            </ListBox.Items>
        </ListBox>

标红的地方可能存在为题,但不知道什么问题,能编译通过执行的时候报错!

问题补充:

报错信息如下:

无法创建在程序集“WPFSETZ, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”中定义的“MainWindow”的实例。 调用的目标发生了异常。  标记文件中“MainWindow.xaml”行1位置9处的错误。

Bj-Soctt-胖仔的主页 Bj-Soctt-胖仔 | 初学一级 | 园豆:70
提问于:2013-11-29 01:01
< >
分享
最佳答案
0

明白了,看代码

<Border >
                                <Border.Style>
                                    <Style>
                                        <Setter Property="Border.Background" Value="Blue"/>
                                        <Style.Triggers>
                                            <Trigger Property="Border.IsMouseOver" Value="true">
                                                <Setter Property="Border.Background" Value="Red"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding UserName}"/>
                                    <TextBlock Text="{Binding Age}"/>
                                </StackPanel>
                            </Border>

 

收获园豆:10
iEvent | 小虾三级 |园豆:529 | 2013-11-29 08:12

谢谢啊,现在效果是有了,但是还有个问题让人很头疼,我在ListBox中绑定List集合数据,但是仅出来一条数据。是咋回事?

Bj-Soctt-胖仔 | 园豆:70 (初学一级) | 2013-12-01 23:48

@Bj-Soctt-胖仔: 怎么绑定的?用范型绑定

iEvent | 园豆:529 (小虾三级) | 2013-12-02 08:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册