Reputation: 1074
I'm making my first Windows Phone 7 App and it's almost done, except for a calculated field in my listbox.
I have a single database with an id, a name, and an integer. I'm using the MVVM pattern. Depending on a function with some calculations, I want yo show YES or NOT as the value of the first field of my ListBox, and the second column is simple the name. How can I show the first field?
This is my code at this moment (for the listbox):
<ListBox x:Name="lstPills" Grid.Row="1" ItemsSource="{Binding AllItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Width="440">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Height="36" Width="60" CornerRadius="5" Background="Grey">
<TextBlock Text="HERE GOES YES or NOT" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="28"/>
</Border>
<TextBlock
Text="{Binding Name}"
FontSize="{StaticResource PhoneFontSizeLarge}"
Grid.Column="1"
VerticalAlignment="Center"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And I have a class with the function that makes the calculation (just a example):
public static bool isRight(int value)
{
return (Math.Abs(value) % 2 == 0 ? true : false);
}
Is there some way to call this function with the bound parameter in the XAML so it reflects the result? Something like:
<TextBlock Text="isRight(Binding myvalue)"/>
I have also my Model and my ViewModel.
Upvotes: 0
Views: 215
Reputation: 5691
try binding this isRight Property
private int _lookupValue;
public bool isRight
{
get {
return (Math.Abs(_lookupValue) % 2 == 0 ? true : false);
}
}
if you think this is still not appliable then you can go with Converters.
Upvotes: 1