WPF-项目调试不常见错误解决

1、问题:调试加载XAML页面时,提示"System.Windows.Markup.XamlParseException"类型的第一次机会异常在PresentationFramework.dll中发生

       解决:请检查ImageSource属性的路径是否正确(即使编译无错),请尝试将改属性项删除,再次调试

2、问题:xaml UI界面控件引用样式(Dictionary.xaml中样式本身无问题)出现混乱的问题。即xaml文件自身样式不设置键名(x:Key),则会影响引用资源文件中样式的部分样式,如下端代码

<!--UI xaml 自身的样式-->
<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionary.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
           <!-- <Style TargetType="TextBlock"> --  这段句会出问题,应使用下句-->
            <Style x:Key="TextBlockStyleDefault" TargetType="TextBlock">
                <Setter Property="TextWrapping" Value="NoWrap"/>
                <Setter Property="TextTrimming" Value="None"/>
                <Setter Property="Margin" Value="10,10,0,0"/>
                <Setter Property="FontSize" Value="16"/>
                <Setter Property="Foreground" Value="#ccdffd"/>
            </Style>
        </ResourceDictionary>    

<!--UI xaml  控件引用-->
<!--此时需要注明 Style 属性值-->
<TextBlock Text="类型:"  Style="{DynamicResource TextBlockStyleDefault}"/>
<!--如果不将自身样式命名,则会影响到 "ComboBoxStyleQuery" 中文本的显示问题-->
<ComboBox x:Name="cmbProviderName" SelectedValuePath="Value" Style="{DynamicResource ComboBoxStyleQuery}" Margin="0,0,0,0"/>

  

posted on 2018-11-15 15:31  xbj_hyml  阅读(641)  评论(0编辑  收藏  举报

导航