반응형
WPF-콤보 상자에 정적 항목 추가
나는 전에 그것을 말했고 나는 그것을 다시 말할 것이다. WPF의 가장 쉬운 예는 또한 웹에서 찾기가 가장 어렵다. :)
표시해야하는 콤보 상자가 있지만 데이터 바인딩 또는 다른 항목 일 필요는 없으며 콘텐츠는 정적입니다. XAML을 사용하여 콤보 상자에 정적 항목 목록을 추가하려면 어떻게해야합니까?
다음은 MSDN의 코드와 자세한 내용을 확인해야하는 기사 링크 입니다.
<ComboBox Text="Is not open">
<ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
<ComboBoxItem Name="cbi2">Item2</ComboBoxItem>
<ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>
이렇게 :
<ComboBox Text="MyCombo">
<ComboBoxItem Name="cbi1">Item1</ComboBoxItem>
<ComboBoxItem Name="cbi2">Item2</ComboBoxItem>
<ComboBoxItem Name="cbi3">Item3</ComboBoxItem>
</ComboBox>
코드에 항목을 추가 할 수도 있습니다.
cboWhatever.Items.Add("SomeItem");
또한 디스플레이 / 값을 제어하는 곳에 무언가를 추가하려면 (제 경험상 거의 절대적으로 필요함) 그렇게 할 수 있습니다. 여기서 좋은 stackoverflow 참조를 찾았습니다.
요약 코드는 다음과 같습니다.
ComboBox cboSomething = new ComboBox();
cboSomething.DisplayMemberPath = "Key";
cboSomething.SelectedValuePath = "Value";
cboSomething.Items.Add(new KeyValuePair<string, string>("Something", "WhyNot"));
cboSomething.Items.Add(new KeyValuePair<string, string>("Deus", "Why"));
cboSomething.Items.Add(new KeyValuePair<string, string>("Flirptidee", "Stuff"));
cboSomething.Items.Add(new KeyValuePair<string, string>("Fernum", "Blictor"));
<ComboBox Text="Something">
<ComboBoxItem Content="Item1"></ComboBoxItem >
<ComboBoxItem Content="Item2"></ComboBoxItem >
<ComboBoxItem Content="Item3"></ComboBoxItem >
</ComboBox>
참고 URL : https://stackoverflow.com/questions/1791784/wpf-add-static-items-to-a-combo-box
반응형
'your programing' 카테고리의 다른 글
Node.js에서 실행되는 javascript에서 NPM 패키지를 설치할 수 있습니까? (0) | 2020.10.07 |
---|---|
Jenkins : 파이프 라인 단계에서 변수를 정의 할 수 없습니다. (0) | 2020.10.07 |
iOS 키 체인이 백그라운드에서 값을 검색하지 않음 (0) | 2020.10.07 |
UrlScan없이 Azure / IIS7에서 과도한 HTTP 응답 헤더 제거 / 숨기기 / 비활성화 (0) | 2020.10.07 |
장고 데이터베이스 쿼리 : ID로 객체를 얻는 방법? (0) | 2020.10.07 |