1
votes

I searched the documentation but apparently there is no PriorityBinding for Windows Phone 8. Is there a similar way to achieve the same behaviour in XAML in Windows Phone 8?

I've created a Style for a 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>

Now I want to add a PriorityBinding, so if the ImageSource or Text are empty I want to add placeholders.

I found this example for 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>

I tried to add PriorityBinding to my ImageSource in the App.xaml and the following error occurs:

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

Edit

I want to bind the ImageSource to the ImageSource property of my model, and if there is no data, then I want to use a placeholder as image instead of the (empty) ImageSource of my model.

The same goes for my TextBlock, if the text in my model is empty I want to display a placeholder text (e.g. "no data").

1
you don't need this propterty for bind image :) Just create string property and : <textblock text="{Binding text, mode=twoway}" /> <image source="{Binding ImageUri}" /> Edit : What do you want to do? i think i don't understand sorry :$MatDev8
@MatDevWp8 I edited my post, hope it helps ;)Tobias Helbich
you could implement the PriorityBinding class yourself...John Gardner

1 Answers

1
votes

hoo ok i think you need to use converter, if i understand ^^

<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();
        }
    }