ListView问题在启动时出现异常 [英] ListView issue getting exception on startup

查看:61
本文介绍了ListView问题在启动时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量调试,没有MICROSOFT在异常详细信息中提供的任何信息,我终于从同一个代码投影仪中收到了一个好主意.我从视图中拉出所有表单,直到加载完毕,然后开始慢慢将它们放回原处.我现在已经隔离了令人反感的代码.如果异常可以将我指向该异常发生时处理的表单,那么肯定会节省时间!
因此,这里的观点令人反感..更改了如何在CodeProject上的一篇文章之后应用模板.

After a great deal of debugging with NO INFORMATION PROVIDED BY MICROSOFT in the exception details, I finally received a great idea from a fellow code projecter. I pulled out all forms from the view until it loaded then began slowly putting them back. I now have isolated the offending code. It sure would save time if the exception could point me to the form that was processed at the time of this exception!
So here is the view that is barfing..changed how the template is applied following an article here on CodeProject.

<UserControl x:Class="Servpro.Framework.ViewerModule.Views.MenuView"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 

             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 

             mc:Ignorable="d" 

             d:DesignHeight="580" d:DesignWidth="210">
    <UserControl.Resources>
        <Style TargetType="ListView">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <TextBlock 
                                removed="Transparent"
                                Foreground="Black" 
                                FontSize="12" 
                                Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" />
                            <TextBlock 
                                removed="Transparent"
                                Foreground="Black" 
                                FontSize="12" 
                                Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8" 
                                    Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
                                    Margin="0,0,10,0" />
                                <TextBlock
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8"
                                    Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" />
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8"
                                    Text=":" />
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8" 
                                    Text="{Binding Path=CurrentEvent.Method, Mode=OneWay}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid Margin="4">
        <ListView 

            ItemsSource="{Binding Path=EventList, Mode=OneWay}" 

            Height="568" VerticalAlignment="Top" 

            Width="201" HorizontalAlignment="Left" 

            Margin="4" >
            <Border CornerRadius="11" />
            <ListView.BorderBrush >
                <SolidColorBrush Color="#99FFFFFF" Opacity="0" />
            </ListView.BorderBrush>
            <ListView.Background>
                <SolidColorBrush Color="#99FFFFFF" Opacity="0"/>
            </ListView.Background>
        </ListView>
    </Grid>
</UserControl>



后面的代码与以前没有改变..注入视图模型和公共属性以在DataContext中设置模型.我发现必须更改设置DataContext的顺序.现在我得到一个例外
为ItemCollection类型的集合添加值会出现异常.使用ItemsSource时操作无效.使用ItemsControl.ItemsSource访问和修改元素.但是我没有在ItemCollection中放任何东西!



The code behind hasn''t changed from before .. injection of a view model and a public property to set the model in the DataContext. I found I had to change my order for setting DataContext. Now I get an exception
Add value to collection of type ItemCollection thre an exception. Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource. But I''m not putting anything in ItemCollection!

Ideas on how this is happening?

推荐答案

好,基于我们最近的对话,我希望这是解决方案.

1)删除以下内容:

Ok, based on our recent conversations I hope this was the solution.

1) remove the following:

<border cornerradius="11" />



2)将border元素重新添加到以下内容中:



2) add the border element back into the following:

<listview.borderbrush>
                <solidcolorbrush color="#99FFFFFF" opacity="0" />
            </listview.borderbrush>
            <listview.background>
                <solidcolorbrush color="#99FFFFFF" opacity="0" />
            </listview.background>
            <listview.view>
                <border cornerradius="11" />
                ....
            </listview.view>


这篇关于ListView问题在启动时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆