小编Use*_*621的帖子

从ResourceDictionary设置WindowStartupLocation会抛出XamlParseException

当我尝试WindowStartupLocation通过a Setter内设置属性时ResourceDictionary,我得到一个XamlParseException:

'Set property'System.Windows.Setter.Property'引发了异常.' 行号'x'和行位置'y'.

内部异常是ArgumentNullException:

值不能为空.参数名称:property.

我在资源字典中的风格是:

<Style TargetType="Window" x:Key="WindowStyle">
    <Setter Property="SizeToContent" Value="WidthAndHeight" />
    <Setter Property="ResizeMode" Value="CanMinimize" />
    <Setter Property="WindowStartupLocation" Value="CenterOwner" />
</Style>
Run Code Online (Sandbox Code Playgroud)

问题不在于使用ResourceDictionary,因为当我删除它时WindowStartupLocation,其他两个属性(SizeToContent和ResizeMode)在引用样式的窗口上按预期设置:

<Window x:Class="WpfApplication1.MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Style="{DynamicResource WindowStyle}">
    <Window.Resources>
        <ResourceDictionary Source="MyResourceDictionary.xaml" />
    </Window.Resources>
</Window>
Run Code Online (Sandbox Code Playgroud)

有没有遇到过这个?它是WPF的错误/限制吗?

PS我知道这个问题类似于资源字典中的Window Startup Location,但是在其他问题中没有提供足够的信息,后来仍未解决.

c# wpf .net-4.0 resourcedictionary

7
推荐指数
2
解决办法
4893
查看次数

标签 统计

.net-4.0 ×1

c# ×1

resourcedictionary ×1

wpf ×1