c# - 尝试在 Visual Studio 2008 中编辑 UI 时出现 WPF Designer 异常

标签 c# wpf visual-studio-2008 data-binding xaml

我的机器上安装了带有 .net 3.5 SP1 的 VS2008,我编写了一个带有两个 ListView 和数据绑定(bind)的简单应用程序,我的应用程序编译正常并且能够运行它,但是当我尝试打开设计器来编辑控件时,我收到以下错误。 我不明白为什么会这样。任何想法...请参阅此错误消息下方的 xaml

Type 'MS.Internal.Permissions.UserInitiatedNavigationPermission' in Assembly 'PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable. at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm) at System.AppDomain.Serialize(Object o) at System.AppDomain.MarshalObject(Object o) at System.Threading.CompressedStack.GetDomainCompressedStack(SafeCompressedStackHandle compressedStack, Int32 index) at System.Security.PermissionListSet.CreateCompressedState(CompressedStack cs, CompressedStack innerCS) at System.Threading.CompressedStack.CompleteConstruction(CompressedStack innerCS) at System.Threading.CompressedStack.GetCompressedStack(StackCrawlMark& stackMark) at System.Security.SecurityContext.Capture(ExecutionContext currThreadEC, StackCrawlMark& stackMark) at System.Threading.ExecutionContext.Capture(StackCrawlMark& stackMark) at System.Threading.ExecutionContext.Capture() at System.Windows.Threading.Dispatcher.BeginInvokeImpl(DispatcherPriority priority, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.BeginInvoke(DispatcherPriority priority, Delegate method, Object arg) at System.Windows.Input.CommandManager.RaiseRequerySuggested() at System.Windows.Input.CommandManager.InvalidateRequerySuggested() at Microsoft.Windows.Design.Interaction.Tool.TaskCollection.InsertItem(Int32 index, Task item) at System.Collections.ObjectModel.Collection`1.Add(T item) at Microsoft.Windows.Design.Interaction.SelectionTool..ctor() at MS.Internal.Providers.VSActiveToolProvider.SelectionToolFactory.TryCreateTool[T](T& tool) at MS.Internal.Host.ToolSubsystem.ActivateTool(ToolFactory toolFactory) at MS.Internal.Host.ToolSubsystem..ctor(EditingContext editingContext, DesignerContext designerContext) at MS.Internal.Host.Designer.Load() at MS.Internal.Designer.VSDesigner.Load() at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedView.Load() at MS.Internal.Designer.VSIsolatedDesigner.VSIsolatedDesignerFactory.Load(IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.BootstrapProxy.LoadDesigner(IsolatedDesignerFactory factory, IsolatedView view) at MS.Internal.Host.Isolation.IsolatedDesigner.Load() at MS.Internal.Designer.DesignerPane.LoadDesignerView()

XAML:

<Grid Name="pngrid_Base" Height="auto" Width="auto" Background="Beige">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" MinWidth="221"></ColumnDefinition>
        <ColumnDefinition Width="auto" MinWidth="1" MaxWidth="1"></ColumnDefinition>
        <ColumnDefinition Width="auto"></ColumnDefinition>
    </Grid.ColumnDefinitions>
        <Grid Name="pngrid_BaseForAll" Grid.Column="0" Width="auto" HorizontalAlignment="Left" Background="#FFD8E4F8">
     <Grid.RowDefinitions>
        <RowDefinition Height="30*"/>
        <RowDefinition Height="164*" />
        <RowDefinition Height="35*" />
        <RowDefinition Height="164*" />
        <RowDefinition Height="40*" />
    </Grid.RowDefinitions>
        <ListView  Name="lstview_Unack" Grid.Row="1" Margin="2,0,0,0" SelectionMode="Extended"  LostFocus="lstview_Unack_LostFocus" 
                                                                                                MouseRightButtonDown="lstview_Unack_MouseRightButtonDown">

            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
        <Button Grid.Row="2" HorizontalAlignment="Left" Margin="24,14,0,5" Name="btnFreeze">Freeze</Button>
            <Button Grid.Row="2" HorizontalAlignment="Left" Margin="12,7,0,5" Name="btnAcknowledge" Width="96">Acknowledge</Button>
        <ListView  Name = "lstview_Ack" Grid.Row="3" Margin="2,1,0,0" LostFocus="lstview_Ack_LostFocus" SelectionMode="Extended" MouseRightButtonDown="lstview_Ack_MouseRightButtonDown">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />                            
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>


        <Button Grid.Row="4" HorizontalAlignment="Left" Margin="16,12,0,7" Name="Clear" Width="78">Clear</Button>
    <TextBox Margin="110,6,32,5" Name="FilterText" TextChanged="FilterText_TextChanged" />
    <ComboBox HorizontalAlignment="Left" Margin="14,5,0,4" Name="comboColumnList" Width="94" />
</Grid>
    <GridSplitter Grid.Column="1" Name="gridSplitter1" Width="2" HorizontalContentAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" Background="Azure" />
    <Grid Name="pnGridForTreeView" Grid.Column="2" Width="200" Grid.ColumnSpan="2">
        <my:TrinityDeviceTree  x:Name ="m_objDeviceTree" Height="auto" Width="auto">

        </my:TrinityDeviceTree>
    </Grid>

</Grid>

最佳答案

我已经使用 .NET 3.5 SP1 在 VS2008 中测试了您的代码,如果我删除了 TrinityDeviceTree 的声明,它可以与设计器一起正常工作。 也许您应该查看该 UserControl 并在那里查找错误。还要尝试清理您的项目并重新构建,有时它可以解决视觉设计师的问题。

关于c# - 尝试在 Visual Studio 2008 中编辑 UI 时出现 WPF Designer 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/494782/

相关文章:

c# - .Net 添加索引到数据表(数据集)

c# - 将数据表中的多行连接到数组中

wpf - 绑定(bind)是否仅适用于 DependencyProperty?

asp.net - VS2008 : Copy Web Site from command line

c# - Crystal 报表分组页尾

c++ - 如何让 C++ 使用我自己的自定义 malloc?

c# - 为什么我的测试一起运行时会失败,但单独运行时会通过?

c# - 字典使用不当?

wpf - 带有附加属性的模板绑定(bind)

WPF ListView 项目单击的名称