wpf PresentationFramework.dll 中发生了“System.Windows.Markup.XamlParseException”类型的第一次机会异常?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24487399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:02:01  来源:igfitidea点击:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll?

c#wpfxamlxamlparseexception

提问by CodeSniper

Hi guys i am facing an exception in the following code,this code was working fine but i dont understand what happened to it now: Exception is :

大家好,我在以下代码中遇到异常,此代码运行良好,但我现在不明白发生了什么:异常是:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: Provide value on 'System.Windows.StaticResourceExtension' threw an exception.



<UserControl x:Class="AFIC.View.WirelessConfigurationView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:res="clr-namespace:AFIC.Resources"
                 xmlns:view="clr-namespace:AFIC.View"
                 xmlns:viewmodel="clr-namespace:AFIC.ViewModel"
                >
        <UserControl.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Height"               Value="30"/>
            <Setter Property="FontFamily"           Value="Arial"/>
            <Setter Property="FontSize"             Value="13"/>
            <Setter Property="FontWeight"           Value="Bold"/>
            <Setter Property="Foreground"           Value="Black"/>

            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="Transparent">

                            <ContentPresenter
                x:Name="contentPresenter"
                ContentTemplate="{TemplateBinding ContentTemplate}"
                Content="{TemplateBinding Content}"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="400"  />
        </Grid.RowDefinitions>

        <ScrollViewer Grid.Row="1" Margin="0,10">
            <StackPanel Height="550"   Orientation="Vertical" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>

                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="170"/>
                        <ColumnDefinition Width="200"/>
                        <ColumnDefinition Width="65"/>
                        <ColumnDefinition Width="205"/>

                    </Grid.ColumnDefinitions>

                    <Label
              Grid.Row="0"
              Grid.ColumnSpan="1"
              HorizontalAlignment="Left"
              Content="IP Configuration:"
              Foreground="Black"
              FontWeight="ExtraBold"
              FontSize="14"
              Opacity="0.8"  
            />

                    <Label
             Grid.Row="1"
             Grid.Column="0"
             VerticalAlignment="Center"
             Content="Wireless IP Address"
             Foreground="Black"
             Opacity="0.8"  
             />
                    <Grid
                Grid.Column="1" 
                Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="40"/>
                            <ColumnDefinition Width="40"/>
                            <ColumnDefinition Width="40"/>
                            <ColumnDefinition Width="40"/>
                        </Grid.ColumnDefinitions>
                        <TextBox
            Grid.Row="1"
            Grid.Column="0"
            VerticalAlignment="Center"
            MaxLength="3" 
            Width="30" 
            Foreground="Black"
            Opacity="0.8"
            Text="{Binding WirelessIP1,UpdateSourceTrigger=PropertyChanged}"
           />
                        <TextBox
            Grid.Row="1"
            Grid.Column="1"
            VerticalAlignment="Center"
            MaxLength="3" 
            Width="30" 
            Foreground="Black"
            Opacity="0.8"
            Text="{Binding WirelessIP2,UpdateSourceTrigger=PropertyChanged}"
           />
                        <TextBox
            Grid.Row="1"
            Grid.Column="2"
            VerticalAlignment="Center"
            MaxLength="3" 
            Width="30" 
            Foreground="Black"
            Opacity="0.8"
            Text="{Binding WirelessIP3,UpdateSourceTrigger=PropertyChanged}"
           />
                        <TextBox
            Grid.Row="1"
            Grid.Column="4"
            VerticalAlignment="Center"
            MaxLength="3" 
            Width="30" 
            Foreground="Black"
            Opacity="0.8"
            Text="{Binding WirelessIP4,UpdateSourceTrigger=PropertyChanged}"
           />
                    </Grid>

                    <Label
             Grid.Row="2"
             Grid.ColumnSpan="1"
             HorizontalAlignment="Left"
             Content="AP Group Configuration"
             Foreground="Black"
             FontWeight="ExtraBold"
             FontSize="14"
             Opacity="0.8"  
             />

                    <Label
             Grid.Row="3"
             Grid.Column="0"
             VerticalAlignment="Center"
             Content="Group ID"
             Foreground="Black"
             Opacity="0.8"  
             Margin="0,0,0,5"
             />

                    <TextBox
            Grid.Row="3"
            Grid.Column="1"
            VerticalAlignment="Center"
            Margin="0,0,0,5"
            Text="{Binding GroupId,UpdateSourceTrigger=PropertyChanged}"
           />

                    <Label
             Grid.Row="3"
             Grid.Column="2"
             VerticalAlignment="Center"
             Content="(1-1024)"
             Foreground="Black"
             Opacity="0.8"  
             Margin="0,0,0,5"
             />

                    <Label
             Grid.Row="4"
             Grid.Column="0"
             VerticalAlignment="Center"
             Content="AP Hardware Type"
             Foreground="Black"
             Opacity="0.8"  
             />

                    <ComboBox
            Grid.Row="4"
            Grid.Column="1"
            ItemsSource="{Binding AvailableHwTypes}" 
            SelectedItem="{Binding SelectedApHardwareType}"
            >
                    </ComboBox>

                    <Button
            Grid.Row="4"
            Grid.Column="2"
            Margin="10,0,0,0"
                        Command=""
            Style="{StaticResource AddHwType}">
                        Add
                    </Button>
                    <Button
            Grid.Row="6"
            Grid.Column="3"
            Margin="10,0,0,0"
            Style="{StaticResource AppButtons}"
            Command="{Binding ConfigWireless}">
                        Configuration
                    </Button>

                    <TextBox 
            Grid.Row="5"
            Grid.ColumnSpan="3"
            IsReadOnly="True"
            IsEnabled="False"
            Visibility="Hidden"
            Height="10"/>

                    <DataGrid 
                  Grid.Row="6"
                  Grid.ColumnSpan="3"
                  Height="100"
                  AutoGenerateColumns="False"
                  ItemsSource="{Binding wirelessconfiguration}"
                  SelectedValue="{Binding SelectedWireless}"
                  Name="dg"
                  >
                        <DataGrid.Columns>
                            <DataGridTextColumn Width="100"  Header="S.No" Binding="{Binding Path=S_No}"/>
                            <DataGridTextColumn Width="100"  Header="Group ID" Binding="{Binding Path=_groupId}"/>
                            <DataGridTextColumn Width="200" Header="AP Hardware Type" Binding="{Binding Path=_apHardwareType}"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <Label
             Grid.Row="7"
             Grid.Column="0"
             HorizontalAlignment="Left"
             Content="Network Configuration"
             FontWeight="ExtraBold"
             Foreground="Black"
             FontSize="14"
             Opacity="0.8"  
             />

                    <Label
             Grid.Row="8"
             Grid.Column="0"
             VerticalAlignment="Center"
             Content="SSID"
             Foreground="Black"
             Opacity="0.8"  
             />

                    <TextBox
            Grid.Row="8"
            Grid.Column="1"
            VerticalAlignment="Center"
            Text="Guest Network"
           />

                    <Label
             Grid.Row="9"
             Grid.Column="0"
             VerticalAlignment="Center"
             Content="Security"
             Foreground="Black"
             Opacity="0.8"  
             />
                    <ComboBox 
                        Margin="0,5,0,8"
                Grid.Row="9"
                Grid.Column="1"
                ItemsSource="{Binding ACAvailableSecurityTypes}"
                SelectedItem="{Binding ACSelectedSecurityType}"
                >

                    </ComboBox>

                    <view:ACSecurityStaticWEP

                Grid.Row="11"
                Grid.ColumnSpan="3"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Visibility="{Binding IsACStaticWep, Converter={StaticResource BooleanToVisibilityConverter}}"
                />
                    <view:ACSecurityTypeWepIEEE

                Grid.Row="11"
                Grid.ColumnSpan="3"
                HorizontalAlignment="Center"
                 VerticalAlignment="Center"
                Visibility="{Binding IsACWEPIEEE, Converter={StaticResource BooleanToVisibilityConverter}}"
                />
                    <view:ACSecurityTypeWPAUC

                Grid.Row="11"
                Grid.ColumnSpan="3"
                 HorizontalAlignment="Center"
                 VerticalAlignment="Center"
                Visibility="{Binding IsACWPAPersonal, Converter={StaticResource BooleanToVisibilityConverter}}"
                />
                    <view:ACSecurityTypEnterprise

                Grid.Row="11"
                Grid.ColumnSpan="3"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Visibility="{Binding IsACWPAEnterprise, Converter={StaticResource BooleanToVisibilityConverter}}"
                />
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>

Can anyone tell me where is the problem.Any help would be highly appreciable.

谁能告诉我问题出在哪里。任何帮助都将非常值得赞赏。

采纳答案by CodeSniper

Solved:I was using wrong Static Resourcei was writingStyle="{StaticResource AddHwType }"and it should be Style="{StaticResource AppButtons}":)

解决:我用错了Static Resource我写的Style="{StaticResource AddHwType }",它应该是Style="{StaticResource AppButtons}":)

回答by Bas

It seems that one of the StaticResources used does not exist:

似乎StaticResource使用的s之一不存在:

Either:

任何一个:

  1. AddHwType(Button Style)
  2. AppButtons(Button Style)
  3. BooleanToVisibilityConverter(Converter)
  1. AddHwType(按钮样式)
  2. AppButtons(按钮样式)
  3. BooleanToVisibilityConverter(转换器)

You might miss a merged dictionary somewhere or forgot to add a resource before using it. Review the XAML Resources page on MSDNfor more info.

您可能会在某处错过合并的字典或在使用之前忘记添加资源。查看MSDN 上XAML 资源页面了解更多信息。