类型' System.Windows.Markup.XamlParseException'的第一次机会异常。发生在PresentationFramework.dll?

时间:2014-06-30 09:54:09

标签: c# wpf xaml xamlparseexception

大家好我在下面的代码中遇到异常,这段代码工作正常,但我不明白现在发生了什么: 例外是:

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>

任何人都可以告诉我问题在哪里。任何帮助都会非常明显。

2 个答案:

答案 0 :(得分:3)

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

或者:

  1. AddHwType(按钮样式)
  2. AppButtons(按钮样式)
  3. BooleanToVisibilityConverter(转换器)
  4. 您可能会错过某处的合并字典,或者在使用之前忘记添加资源。查看XAML Resources page on MSDN了解详情。

答案 1 :(得分:0)

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