我是 WPF 的新手,我在網(wǎng)上閱讀了很多類似的問題,但我仍然沒有讓我的列表視圖工作。我想根據(jù)屬性(紅色、黃色或綠色)更改列表視圖元素的背景顏色在itemsSource我的ListView的是這個類的一個觀察的名單:public class ConnectionItem { public ConnectionItem(string name) { Name = name; } public string Name { get; } private string _color = "Red"; public string Color { get => _color; } private ConnectionStatus _status; public ConnectionStatus Status { set { if (value == _status) { return; } else { switch (value) { case ConnectionStatus.Connected: _color = "Yellow"; break; case ConnectionStatus.Ready: _color = "Green"; break; default: _color = "Red"; break; } } } }}我在 xaml 中定義了我的列表視圖,如下所示:<ListView x:Name="lvConnections"> <ListView.ItemContainerStyle> <Style TargetType="{x:Type ListViewItem}"> <EventSetter Event="MouseDoubleClick" Handler="ListViewItem_MouseDoubleClick" /> </Style> </ListView.ItemContainerStyle> <ListView.Resources>綁定不起作用,我所有的列表視圖元素都沒有背景顏色。我不需要通過ListView.Resources綁定完全相同的解決方案,但我在其他方法中也沒有成功。
- 3 回答
- 0 關(guān)注
- 274 瀏覽
添加回答
舉報
0/150
提交
取消