WPF样式异常

时间:2019-05-03 06:38:11

标签: wpf vb.net

今天,我试图将我的应用程序发布到新安装的Windows 10 PC上,但是在尝试寻找导致这种情况的原因数小时后,我却遇到了异常:

  

其他信息:“设置属性'System.Windows.FrameworkElement.Style'引发异常。”行号“ 3466”和行位置“ 50”。

第3466行的代码是:

     <ComboBox x:Name="brojevidokumenatacbox" Margin="0,106,102,0" Style="{DynamicResource ComboBoxStyle2}" VerticalAlignment="Top" Height="43"  ItemsPanel="{DynamicResource ItemsPanelTemplate3}" Background="#FF3C3C3C" BorderBrush="#FF5F3333" ItemTemplate="{DynamicResource DataTemplate1}" ItemContainerStyle="{DynamicResource ComboBoxItemStyle3}" HorizontalAlignment="Right" Width="184">
        <ComboBoxItem Content="ComboBoxItem" HorizontalAlignment="Left" Width="258" Style="{DynamicResource ComboBoxItemStyle2}"/>
    </ComboBox>

具体来说,导致异常的部分是:Style =“ {DynamicResource ComboBoxStyle2}”

这是样式:

   <Style x:Key="ComboBoxStyle2" TargetType="{x:Type ComboBox}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
        <Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Padding" Value="6,3,5,3"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
        <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
        <Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
        <Style.Triggers>
            <Trigger Property="IsEditable" Value="true">
                <Setter Property="IsTabStop" Value="false"/>
                <Setter Property="Padding" Value="2"/>
                <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

为什么会这样?

0 个答案:

没有答案