簡體   English   中英

如何在Metro UI XAML中聲明空字符串

[英]How to declare empty string in Metro UI XAML

我正在嘗試在WinRT DataTriggers中編寫簡單替換缺失的內容,例如:

<dt:DataTrigger Property="Message" Value="">
    <dt:Setter TargetName="tbMessage" Property="Visibility" Value="Collapsed" />
</dt:DataTrigger>

所以我有類DataTrigger,其屬性值在XAML中設置。 我需要將Value設置為string.Empty。 當我使用“”(空括號)時,Value設置為null,而不是string.Empty。 我試過在Resources中定義空字符串:

<x:String x:Key="EmptyString"></x:String>

並使用它

<dt:DataTrigger Property="Message" Value="{StaticResource EmptyString}">
    <dt:Setter TargetName="tbMessage" Property="Visibility" Value="Collapsed" />
</dt:DataTrigger>

值仍設置為null。 我也嘗試使用下一個代碼:

xmlns:sys="using:System" ... <sys:String x:Key="EmptyString"></sys:String>

此代碼拋出異常“mscorlib.dll中發生類型'Windows.UI.Xaml.Markup.XamlParseException'的異常,但未在用戶代碼中處理

WinRT信息:找不到類型'String'。“

使用<x:Static Member="sys:String.Empty" />方法無法使用,因為在WinRT x:Static缺失。

甚至可以在WinRT XAML中聲明一個空字符串?

嘗試這個

<TextBlock Text="{x:Static System:String.Empty}" Name="emptyString"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM