코드에서 목록 상자의 배경색을 설정하려고합니다. 목록 상자 항목을 사용하여 작업 할 수는 있지만 목록 상자는 사용할 수 없습니다. 여기 WPF - ListBox 배경색 - CodeBehind
합니다 (ListBoxItem의와 함께) 작동하는 코드입니다 : 내가옵니다 자체 작업을 시도하는 코드를 변경하는 경우, 지금 private void SetBackgroundGradient()
{
var styleListBox = new Style(typeof(ListBoxItem));
var myBrush = new LinearGradientBrush();
myBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 0.0));
myBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 255, 255), 1.0));
styleListBox.Setters.Add(new Setter
{
Property = BackgroundProperty,
Value = myBrush
});
lstTopics.ItemContainerStyle = styleListBox;
}
, 내가 할 모든 흰색 배경입니다. 그 코드는 다음과 같습니다.
private void SetBackgroundGradient()
{
var styleListBox = new Style(typeof(ListBox));
var myBrush = new LinearGradientBrush();
myBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 0.0));
myBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 255, 255, 255), 1.0));
styleListBox.Setters.Add(new Setter
{
Property = BackgroundProperty,
Value = myBrush
});
lstTopics.Style = styleListBox;
}
내가 뭘 잘못하고 있을지 모릅니다.
내가 묻는 것에 대해 설명이 필요하면 알려 주시기 바랍니다.
미리 감사드립니다.
샘플 코드는 나를 위해 잘 작동
감사하지 않는 코드를 통해 그라데이션으로 목록 상자의 배경을 설정할 수 있습니다. 어쩌면 함수를 호출하는 곳에 비트를 추가하고 XAML을 추가 할 수 있습니까? –
와우, 목록 상자의 배경을 설정할 수 있었습니까? 흥미 롭습니다 ...리스트 박스만으로 새로운 프로젝트를 만들고 주 프로젝트에서 뭔가 잘못하고 있는지 보도록하겠습니다. – CodeLikeBeaker