0

初めての Windows Phone 7 アプリを作成していますが、リスト ボックスの計算フィールドを除いてほぼ完成しています。

ID、名前、および整数を持つ単一のデータベースがあります。私はMVVMパターンを使用しています。いくつかの計算を伴う関数に応じて、ListBox の最初のフィールドの値として YES または NOT を表示し、2 番目の列は単純な名前にする必要があります。最初のフィールドを表示するにはどうすればよいですか?

これは現時点での私のコードです(リストボックス用):

    <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 でバインドされたパラメーターを使用してこの関数を呼び出す方法はありますか? 何かのようなもの:

<TextBlock Text="isRight(Binding myvalue)"/>

Model と ViewModel もあります。

4

1 に答える 1

1

この isRight プロパティをバインドしてみてください

private int _lookupValue;
public bool isRight
    {
      get {
        return (Math.Abs(_lookupValue) % 2 == 0 ? true : false);
      }
    }

これがまだ当てはまらないと思われる場合は、Convertersを使用できます。

于 2013-10-07T11:06:18.327 に答える