Xaml Windows Phone 8-优先绑定
我搜索了文档,但显然没有针对Windows Phone 8的PriorityBinding。在Windows Phone 8中,是否有类似的方法在XAML中实现相同的行为? 我已为ListItem创建了一个样式:Xaml Windows Phone 8-优先绑定,xaml,windows-phone-8,Xaml,Windows Phone 8,我搜索了文档,但显然没有针对Windows Phone 8的PriorityBinding。在Windows Phone 8中,是否有类似的方法在XAML中实现相同的行为? 我已为ListItem创建了一个样式: 现在我想添加PriorityBinding,因此如果ImageSource或文本为空,我想添加占位符 我发现了WPF的以下示例: [...] 我试图将PriorityBinding添加到App.xaml中的ImageSource,出现以下错误: 找不到类型“PriorityBi
现在我想添加PriorityBinding,因此如果ImageSource或文本为空,我想添加占位符
我发现了WPF的以下示例:
[...]
我试图将PriorityBinding添加到App.xaml中的ImageSource,出现以下错误:
找不到类型“PriorityBinding”。验证是否缺少部件引用,以及是否已生成所有引用的部件。
编辑
我想将ImageSource绑定到模型的ImageSource属性,如果没有数据,那么我想使用占位符作为图像,而不是模型的(空)ImageSource
我的文本块也是如此,如果我的模型中的文本为空,我想显示一个占位符文本(例如“无数据”)。好的,如果我理解,我想你需要使用转换器^^
<phone:PhoneApplicationPage.Resources>
<Converter:TextConverter x:Key="TextConverter"></Converter:TextConverter>
</phone:PhoneApplicationPage.Resources>
<TextBlock
Grid.Column="1"
TextWrapping="NoWrap"
TextTrimming="WordEllipsis"
Text="{Binding Path=Text,converter{StaticRessource TextConverter}" />
public class TextConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return "No data";
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
公共类TextConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、CultureInfo区域性)
{
if(值!=null)
{
返回“无数据”;
}
返回null;
}
公共对象转换回(对象值、类型targetType、对象参数、CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}
好吧,如果我理解的话,我想你需要使用转换器^^
<phone:PhoneApplicationPage.Resources>
<Converter:TextConverter x:Key="TextConverter"></Converter:TextConverter>
</phone:PhoneApplicationPage.Resources>
<TextBlock
Grid.Column="1"
TextWrapping="NoWrap"
TextTrimming="WordEllipsis"
Text="{Binding Path=Text,converter{StaticRessource TextConverter}" />
public class TextConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return "No data";
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
公共类TextConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、CultureInfo区域性)
{
if(值!=null)
{
返回“无数据”;
}
返回null;
}
公共对象转换回(对象值、类型targetType、对象参数、CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}
绑定图像不需要此属性:)只需创建字符串属性并编辑:您想做什么?我想我不明白对不起:$@MatDevWp8我编辑了我的帖子,希望能有所帮助;)您可以自己实现PriorityBinding
类……绑定图像不需要此属性:)只需创建字符串属性和:编辑:您想做什么?我想我不明白对不起:$@MatDevWp8我编辑了我的帖子,希望能有所帮助;)您可以自己实现PriorityBinding
类…感谢您的快速回答,我会尝试一下(可能在周一,我正在做一些其他的东西),如果这是我需要的,我会将它标记为已回答;)如果(value==null){return“No data”;}我想我必须进一步查看转换器文档才能理解它们,现在我只是在类中添加了propoerties,它转换文本(如果文本为空,则返回“No data”)。但是,ImageSource
s有一个问题-我想从服务器上获取一个图像,当这个图像不显示时,我想显示一个占位符图像。也在ImageSource上绑定文本,然后再次使用转换器。检查值是否为null并返回null或“占位符文本”否?ImageSource的文本不是null或空的,但它将无法加载图像,因为它在服务器上不存在-因此我无法使用转换器。我已经看到了这种情况下的PriorityBinding:第一,加载占位符,第二,加载真实图像(据我所知:如果出现错误,不要显示真实图像-例如404,源为空或空)。感谢快速回答,我将尝试它(可能在周一,我目前正在处理一些其他东西),如果它是我需要的,我将把它标记为已回答;)'如果(value==null){return“No data”;}我想我必须进一步查看转换器文档才能理解它们,现在我只是在类中添加了propoerties,它转换文本(如果文本为空,则返回“No data”)。但是,ImageSource
s有一个问题-我想从服务器上获取一个图像,当这个图像不显示时,我想显示一个占位符图像。也在ImageSource上绑定文本,然后再次使用转换器。检查值是否为null并返回null或“占位符文本”否?ImageSource的文本不是null或空的,但它将无法加载图像,因为它在服务器上不存在-因此我无法使用转换器。我已经看到了这种情况下的PriorityBinding:首先,加载占位符,然后加载真实图像(据我所知:如果出现错误,不要显示真实图像-例如404,源为null或空)。