我正在制作我的第一个Windows Phone 7 App,除了列表框中的一个计算字段外,它几乎完成了。
我有一个具有ID,名称和整数的数据库。我正在使用MVVM模式。根据某些计算的函数,我希望您将YES或NOT作为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>
我有一个进行计算的函数的类(仅作为示例):
public static bool isRight(int value)
{
return (Math.Abs(value) % 2 == 0 ? true : false);
}
有什么方法可以在XAML中使用bound参数来调用此函数,以反映结果吗?就像是:
<TextBlock Text="isRight(Binding myvalue)"/>
我也有我的模型和我的ViewModel。
尝试绑定此isRight属性
private int _lookupValue;
public bool isRight
{
get {
return (Math.Abs(_lookupValue) % 2 == 0 ? true : false);
}
}
如果您认为这仍然不适用,则可以使用Converters。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句