积极答复者
在设计时如何忽略标记?

问题
-
在代码中,我们可以用DesignerProperties。 GetIsInDesignMode来判断设计状态,避免了一些代码正确,界面却无法显示的问题。
现在是:在xaml中我需要添加一些标记,例如国际化的资源字典,因为正式导入是在app。cs中,设计时UI上却显示不了,但是运行时是可以显示的,为了方便设计,我希望在设计时就能看到内容,需要在窗体上加入ResourceDictionary的资源字典,但是运行时希望该代码无效。该如何去做呢?我看见window的设计中有个Ignorable东西,到不知道如何使用到忽略标记上,而不是忽略属性上。
Sonny.Lin
答案
-
- 已建议为答案 Jie BaoModerator 2011年7月5日 9:44
- 已标记为答案 Jie BaoModerator 2011年7月11日 3:05
-
Ig 不是这么用的 这个应该是指忽略自定义的标记,标记版本管理 主要是解决兼容问题
比如 Blend 中的 d: 命名空间 d: 在运行时需要忽略 那么就写做mc:Ignorable:d 就会忽略d下的标记
- 已标记为答案 Jie BaoModerator 2011年7月18日 3:29
全部回复
-
- 已建议为答案 Jie BaoModerator 2011年7月5日 9:44
- 已标记为答案 Jie BaoModerator 2011年7月11日 3:05
-
正确,你可以在运行时将已经在Design时导入的资源Remove 然后在导入你所要的相关语言的资源。
至于Ignorable,适用于忽略所影射的名字空间中的标记的,当然按照你的需求,你就需要对ResourceDictionary这个标记做一次单独的映射:
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:resource="clr-namespace:System.Windows;assembly=PresentationFramework" mc:Ignorable="resource"> <UserControl.Resources> <resource:ResourceDictionary> ...... </resource:ResourceDictionary> </UserControl.Resources> <Grid> </Grid>
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 qing2000 2011年7月10日 14:00
- 取消答案标记 Jie BaoModerator 2011年7月18日 3:36
-
我查了msdn关于mc:Ignorable的用法(http://msdn.microsoft.com/zh-cn/library/aa350024.aspx)和您说的一致,但是实践中没有起效。见我的xaml内容:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="241" Width="379" xmlns:ig="clr-namespace:System.Windows;assembly=PresentationFramework" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="ig" > <Window.Resources> <!--<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ig:ResourceDictionary Source="Style.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>--> <ig:Style TargetType="{x:Type Grid}"> <Setter Property="Background" Value="Blue" /> </ig:Style> </Window.Resources> <Grid /> </Window>
结果运行时Grid还是蓝色,即时使用被注释的代码片段也是蓝色,没有被忽略。这个就比较纳闷了。能否给予指导?
Sonny.Lin -
Ig 不是这么用的 这个应该是指忽略自定义的标记,标记版本管理 主要是解决兼容问题
比如 Blend 中的 d: 命名空间 d: 在运行时需要忽略 那么就写做mc:Ignorable:d 就会忽略d下的标记
- 已标记为答案 Jie BaoModerator 2011年7月18日 3:29
-
我的确是错了, 文档上如是说:
mc:Ignorable 仅应用于命名空间与标识符字符串的映射。mc:Ignorable 并不应用于命名空间与程序集的映射
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.