이것은 Windows 8.1 미리보기 및 Windows 8 개발을위한 것입니다. 이 콤보 박스를 사용하고 개발하기 전에 지금 미리보기를 설치해야합니다. 이 상태 자리 표시 자에 대한 문서를 보면 :
Minimum supported client Windows 8.1 Preview
편집
수동으로이 작업을 수행하려면 단순히 손으로 콤보 상자를 미리로드. 다음의 예는, 생성자가 ComboData에 메인 페이지의 XAML 바인딩에 이제 "로드"
public class MainVM : INotifyPropertyChanged
{
private List<string> _dataList;
public List<string> ComboData
{
get { return _dataList; }
set
{
if (_dataList != value)
{
_dataList = value;
OnPropertyChanged();
}
}
}
public MainVM()
{
ComboData = new List<string> {"Loading..."};
}
#region INotify Property Changed Implementation
/// <summary>
/// Event raised when a property changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Raises the PropertyChanged event.
/// </summary>
/// <param name="propertyName">The name of the property that has changed.</param>
public void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
라는 콤보 상자에 초기 값을로드 할 경우 우리가 ViewModel을 시작하자, 그러나 우리는주의해야 한 항목의 목록에로드가있는 첫 번째 상황이며 선택한 항목을 만들고 싶습니다.
<ComboBox ItemsSource="{Binding ComboData}" Height="30" Width="300" Loaded="OnLoaded" />
좋아, 우리는 전에 우리가 설정 뷰 모델로 우리의 데이터 컨텍스트를 설정뿐만 아니라 한 항목 로딩 확인하는 OnLoaded 방법이있을 것이다 페이지의 코드 숨김 상태. 아래 예제에서 우리는 나머지 데이터를로드하는 데 3 초의 지연을 시뮬레이션합니다.
public sealed partial class MainPage : Page
{
public MainVM ViewModel { get; set; }
public MainPage()
{
this.InitializeComponent();
DataContext = ViewModel = new MainVM();
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
var cBox = sender as ComboBox;
if (cBox != null)
{
if ((cBox.Items != null) && (cBox.Items.Count == 1))
{
cBox.SelectedIndex = 0;
// Debug code to simulate a change
Task.Run(() =>
{
// Sleep 3 seconds
new System.Threading.ManualResetEvent(false).WaitOne(3000);
Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{ ViewModel.ComboData = new List<string> {"Alpha", "Gamma", "Omega"}; });
});
}
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
그래,하지만 내 윈도우 8 응용 프로그램에서 속성과 같은 자리 표시자를 어떻게 사용할 수 있는지 말해주십시오. – Jatin
@Ricky 예제보기 – OmegaMan