Windows Phone 8 - Приоритетное связывание

Я искал документацию, но, по-видимому, нет PriorityBinding для Windows Phone 8. Существует ли аналогичный способ для достижения того же поведения в XAML в Windows Phone 8?

Я создал стиль для ListItem:

<DataTemplate x:Key="ListItem">
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="50" />
        </Grid.ColumnDefinitions>

        <Image 
            Grid.Column="0"
            Source="{Binding Path=ImageSource}" />

        <TextBlock 
            Grid.Column="1" 
            TextWrapping="NoWrap"
            TextTrimming="WordEllipsis"
            Text="{Binding Path=Text}" />

        <Image 
            Grid.Column="2"
            Source="/images/arrow_right.png" />

    </Grid>
</DataTemplate>

Теперь я хочу добавить PriorityBinding, поэтому, если ImageSource или Text пусты, я хочу добавить заполнители.

Я нашел этот пример для WPF:

<Image.Source>
    <PriorityBinding FallbackValue="/images/default_category.png">
        <Binding Path="ImageSource"/>
    </PriorityBinding>
</Image.Source>

[...]

<TextBlock.Text>
    <PriorityBinding FallbackValue="Placeholder Text">
        <Binding Path="Text"/>
    </PriorityBinding>
</TextBlock.Text>

Я попытался добавить PriorityBinding к своему ImageSource в App.xaml, и произошла следующая ошибка:

The type 'PriorityBinding' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

редактировать

Я хочу связать ImageSource со свойством ImageSource моей модели, и если данных нет, я хочу использовать заполнитель в качестве изображения вместо (пустого) ImageSource моей модели.

То же самое касается моего TextBlock, если текст в моей модели пуст, я хочу отобразить текст-заполнитель (например, "нет данных").

1 ответ

Решение

О, хорошо, я думаю, что вам нужно использовать конвертер, если я понимаю ^^

<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();
        }
    }
Другие вопросы по тегам