Ste*_*ett 4 wpf null xaml staticresource
是否可以将null添加为标记元素的静态资源?我希望能够使用{StaticResource myKey}语法引用值.目前,我需要引用的值为null,但将来可能不会.我在标记的其余部分有多个引用值,我希望它们引用资源键而不是{x:Null}.
我希望这样做:
<Window.Resources>
<x:Null key="myKey" />
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
......但这不起作用.它编译但在运行时会引发XamlParseException,表示无法解析资源引用.
这对我来说很好:
<Window x:Class="SO16456565.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--<SolidColorBrush x:Key="BG" Color="AntiqueWhite"/>-->
<x:NullExtension x:Key="BG"/>
</Window.Resources>
<Border Background="{StaticResource BG}"/>
</Window>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1308 次 |
| 最近记录: |