1

次のように xaml でコンボボックスを作成しました。

ComboBox x:Name="cbTest" ItemsSource="{Binding}" SelectedValue="{Binding Test, Mode=TwoWay}" HorizontalAlignment="Left" Margin="0,10,0,0" Width="250" SelectionChanged="cbTest_SelectionChanged"/>

Combobox には次の ItemSource が含まれています。

cbTest.ItemsSource = new string[] { "Left", "Right", "Center" };

Combobox に 3 つの文字列が表示されますが、以前に選択した SelectedValue が表示されません。これはプロパティです:

private short _test;
public short Test
{
    get
    {
        return _test;
    }
    set
    {
        _test = value;
        NotifyPropertyChanged();
    }
}

テストでは、次のデータが得られます:「左」。それで、データを取得しましたが、バインディングが機能していません!

ありがとう!

4

1 に答える 1

1

System.String問題は、 (short)に変換System.Int16できず、「Left」、「Right」、「Center」が数値ではないため、どちらも解析できないことです。

として使用stringしてみてくださいSelectedValue

private string _test;
public string Test
{
    get
    {
        return _test;
    }
    set
    {
        _test = value;
        NotifyPropertyChanged();
    }
}
于 2013-03-08T10:56:48.357 に答える