WPF运行报XamlParseException

编写xmal,并在window.resources节点下添加自己的资源,在Grid中使用该资源,在编译时没有编译警告和错误,但是在运行时报以下错误:

通过查资料,发现原来是将window.resources节点放在了Grid节点下面的原因导致,将资源的申明放在使用之前/或者将资源的引用由静态修改为动态,则不会报错。

 

转载于:https://www.cnblogs.com/chyshx/p/10489259.html

<UserControl x:Class="Motion_YC.Views.LogView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:local="clr-namespace:Motion_YC.Views" d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto" /> <RowDefinition /> </Grid.RowDefinitions> <StackPanel Margin="0,2,0,2" Orientation="Horizontal"> <StackPanel.Resources> <Style x:Key="ToggleButtonLogView" TargetType="ToggleButton" BasedOn="{StaticResource MahApps.Styles.ToggleButton.Flat}"> <Setter Property="Margin" Value="0,0,2,0" /> <Setter Property="Height" Value="26" /> <Setter Property="mah:ControlsHelper.CornerRadius" Value="5" /> <Setter Property="FontSize" Value="13" /> <Setter Property="FontWeight" Value="Normal" /> <Setter Property="Background" Value="{StaticResource MahApps.Brushes.Accent4}" /> <Setter Property="FontFamily" Value="{StaticResource iconfont}" /> <Setter Property="Padding" Value="2" /> <Style.Triggers> <Trigger Property="IsChecked" Value="False"> <Setter Property="Foreground" Value="White" /> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{StaticResource MahApps.Brushes.Accent3}" /> </Trigger> </Style.Triggers> </Style> </StackPanel.Resources> <ToggleButton IsChecked="{Binding InfoFilter}" Style="{StaticResource ToggleButtonLogView}"> <StackPanel Orientation="Horizontal"> <!--<Image Width="16" Height="16" Source="/Assets/Images/Info.png" />--> <TextBlock Margin="5,0" VerticalAlignment="Center"> <Run Text="信息" /> <Run Text="{Binding InfoCount}" /> </TextBlock> </StackPanel> </ToggleButton> <ToggleButton IsChecked="{Binding WarnFilter}" Style="{StaticResource ToggleButtonLogView}"> <StackPanel Orientation="Horizontal"> <!--<Image Width="16" Height="16" Source="/Assets/Images/Warn.png" />--> <TextBlock Margin="5,0" VerticalAlignment="Center"> <Run Text="警告" /> <Run Text="{Binding WarnCount}" /> </TextBlock> </StackPanel> </ToggleButton> <ToggleButton IsChecked="{Binding ErrorFilter}" Style="{StaticResource ToggleButtonLogView}"> <StackPanel Orientation="Horizontal"> <!--<Image Width="16" Height="16" Source="/Assets/Images/Error.png" />--> <TextBlock Margin="5,0" VerticalAlignment="Center"> <Run Text="错误" /> <Run Text="{Binding ErrorCount}" /> </TextBlock> </StackPanel> </ToggleButton> <ToggleButton IsChecked="{Binding AlarmFilter}" Style="{StaticResource ToggleButtonLogView}"> <StackPanel Orientation="Horizontal"> <!--<Image Width="16" Height="16" Source="/Assets/Images/Alarm.png" />--> <TextBlock Margin="5,0" VerticalAlignment="Center"> <Run Text="警" /> <Run Text="{Binding AlarmCount}" /> </TextBlock> </StackPanel> </ToggleButton> </StackPanel> <StackPanel Margin="2" HorizontalAlignment="Right" Orientation="Horizontal"> <Button Width="30" Height="26" Margin="0,0,0,0" FontFamily="{DynamicResource iconfont}" FontSize="18" Background="{StaticResource MahApps.Brushes.Accent4}" BorderBrush="{StaticResource MahApps.Brushes.Accent4}" Click="btnScrollIntoTop_Click" /> <Button Width="30" Height="26" Margin="2,0,0,0" FontFamily="{DynamicResource iconfont}" FontSize="18" Background="{StaticResource MahApps.Brushes.Accent4}" BorderBrush="{StaticResource MahApps.Brushes.Accent4}" Click="btnScrollIntoEnd_Click" /> </StackPanel> <DataGrid Grid.Row="1" AutoGenerateColumns="False" x:Name="dg" EnableColumnVirtualization="True" EnableRowVirtualization="True" VirtualizingPanel.IsVirtualizing="True" ItemsSource="{Binding DisplayLogCollection}" FontSize="12" RowHeaderWidth="20" SelectionUnit="FullRow" HeadersVisibility="Column" GridLinesVisibility="All" IsReadOnly="True" CanUserAddRows="False" > <DataGrid.ContextMenu> <ContextMenu StaysOpen="True"> <MenuItem Header="清空警" Click="ClearAlarm"/> </ContextMenu> </DataGrid.ContextMenu> <DataGrid.Columns> <DataGridTemplateColumn Header="时间" IsReadOnly="True" Width="150"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding CreateTime,StringFormat=\{0:yyyy/MM/dd HH:mm:ss fff\}}" HorizontalAlignment="Left" Foreground="{Binding LogColor}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="类型" IsReadOnly="True" Width="80"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding LogType}" HorizontalAlignment="Left" Foreground="{Binding LogColor}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="日志类容" IsReadOnly="True" Width="*"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Content}" HorizontalAlignment="Left" Foreground="{Binding LogColor}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </Grid> </UserControl>这是源码直接用源码告诉我修改方法
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值