2

我认为下图很好地描述了这个问题。

http://www.webeasy.com.gr/problem.jpg

在我的 windows phone 7 应用程序(C#)中,我有一个组合框,它绑定了一些数据(StatusNameAsceding、StatusNameDesceding 等)

如您所见,下拉列表似乎完全空白,并且其项目显示在下拉列表中,但选定的项目除外。任何想法。

更新... 我使用的代码

对于组合框...(xaml 页面)

<ComboBox SelectionChanged="OnSortingColumnChanged"
x:Name="SortingColumn" Margin="2,0,0,0" Foreground="Black"
VerticalContentAlignment="Center" Padding="0">

在 App.xaml.cs 中

public enum SortingColumns
{
    StatusNameAscending = 0,
    StatusNameDescending,
    EXAMINOAscending,
    EXAMINODescending,
}
public SortingColumns SortingColumn { get; set; }

在后面的代码中(page.xaml.cs)

this.DataContext = CreateSampleData();

App.Current.SortingColumn = App.SortingColumns.StatusNameAscending;
SortingColumn.Items.Add(App.SortingColumns.StatusNameAscending.ToString());
SortingColumn.Items.Add(App.SortingColumns.StatusNameDescending.ToString());
SortingColumn.Items.Add(App.SortingColumns.EXAMINOAscending.ToString());
SortingColumn.Items.Add(App.SortingColumns.EXAMINODescending.ToString());
SortingColumn.SelectedIndex = (int)App.Current.SortingColumn;

和...

private void OnSortingColumnChanged(object sender, SelectionChangedEventArgs e)
{
    App.Current.SortingColumn = (App.SortingColumns)SortingColumn.SelectedIndex;

    // Rebind
    // The List control binds the data again when a different datacontext is set.
    var datacontext = DataContext;
    DataContext = null;
    DataContext = datacontext;
}

UPDATE2 ... 当我单击空白列表时,会发生选择更改并应用排序,我认为组合框模板中发生了错误,但我不知道是什么!任何想法?提前致谢!

4

1 回答 1

0

In the end I used listpicker instead of combobox

<toolkit:ListPicker SelectionChanged="OnSortingColumnChanged" x:Name="SortingColumn" Margin="2,0,0,0" Foreground="Black" Width="300" Height="180" FontSize="18"></toolkit:ListPicker>

A few details...

First of all you must install Silverlight tool for Windows Phone. You can download it here: http://silverlight.codeplex.com/releases/view/71550

Then we go to AnyPage.xaml and built a sample User Interface but after that we declare like so:

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

The rest of the code remains the same. For more information about listpicker take a look here

于 2012-08-31T11:13:25.213 回答