我想设置禁用的ListView的样式。但无论我做什么,listView在禁用时都保持默认样式。
我已尝试过的内容:
SystemColors.ControlBrushKey
设置为Transparent
:Change disabled listbox background to gray DisabledBorderLightColor
所有这些尝试都可以在窗口的资源部分看到:
<Window.Resources>
<Style TargetType="{x:Type ListView}">
<Style.Resources>
<Color x:Key="DisabledBorderLightColor">#FF00FF00</Color>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
</Style.Resources>
<Setter Property="Background" Value="Green"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Content="Unselect" Click="UnselectItem"></Button>
<ListView x:Name="_listView"
Grid.Row="1"
d:DataContext="{d:DesignData ObjectToShow}"
IsEnabled="True"
SelectionChanged="SelectItem">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Header1" DisplayMemberBinding="{Binding Property1}"/>
<GridViewColumn Header="Header2" DisplayMemberBinding="{Binding Property2}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</Grid>
这是根据c#:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var objectsToShow = new List<ObjectToShow>
{
new ObjectToShow
{
Property1 = "Content1Property1",
Property2 = "Content1Property2"
},
new ObjectToShow
{
Property1 = "Content2Property1",
Property2 = "Content2Property2"
},
};
_listView.ItemsSource = objectsToShow;
}
private void SelectItem(object sender, SelectionChangedEventArgs e)
{
_listView.IsEnabled = false;
}
private void UnselectItem(object sender, RoutedEventArgs e)
{
_listView.SelectedItem = null;
_listView.IsEnabled = true;
}
}
public class ObjectToShow
{
public string Property1 { get; set; }
public string Property2 { get; set; }
}
我只希望listView在禁用时具有红色背景。我怎样才能做到这一点?
答案 0 :(得分:2)
将您的CURL* pEasy = nullptr;
pEasy = curl_easy_init();
if (pEasy != nullptr)
{
curl_easy_setopt(pEasy, CURLOPT_USERNAME, user.c_str());
curl_easy_setopt(pEasy, CURLOPT_PASSWORD, pass.c_str());
curl_easy_setopt(pEasy, CURLOPT_URL, urlToConnectTo.c_str());
curl_easy_setopt(pEasy, CURLOPT_WRITEFUNCTION, OnReceiveHttpResponse);
curl_easy_perform(pEasy);
curl_easy_cleanup(pEasy);
}
样式更改为以下内容:
ListView
当你必须覆盖整个控制模板时,它只是为了改变它的一小部分而非常烦人......但有时你却别无选择。
在这种情况下,由于更改背景颜色的触发器位于ControlTemplate中,因此无法使用样式触发器覆盖它。
答案 1 :(得分:0)
我认为你必须定义自己的控件模板来覆盖这个模板的默认ListView模板。
或者你可以试试内置的控制刷是否能满足你的需求:
<ListView.Style>
<Style TargetType="{x:Type ListView}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Crimson"/>
</Style.Resources>
</Style>
</ListView.Style>