第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改所選ListBox項的背景顏色

更改所選ListBox項的背景顏色

一只名叫tom的貓 2019-11-29 11:05:22
到目前為止,這是我的XAML。    <ScrollViewer Grid.Column="1" Grid.RowSpan="2">        <ListBox   Background="Black" ItemsSource="{Binding Path=ActiveLog}" >            <ListBox.ItemTemplate>                <DataTemplate>                    <Grid Background="Black">                        <Grid.ColumnDefinitions>                            <ColumnDefinition Width="200"></ColumnDefinition>                            <ColumnDefinition Width="*"></ColumnDefinition>                        </Grid.ColumnDefinitions>                        <Grid.RowDefinitions>                            <RowDefinition></RowDefinition>                            <RowDefinition></RowDefinition>                        </Grid.RowDefinitions>                        <TextBlock Grid.Column="0" Grid.Row="0" Foreground="White">                            <TextBlock >Date:</TextBlock>                            <TextBlock  Text="{Binding Path=LogDate}"/>                        </TextBlock>                        <TextBlock Grid.Column="1" Grid.Row="0" Foreground="White">                            <TextBlock >Severity:</TextBlock>                            <TextBlock  Text="{Binding Path=Severity}"/>                        </TextBlock>                        <TextBlock Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Foreground="LightGray" Text="{Binding Path=Message}"></TextBlock>                    </Grid>                </DataTemplate>            </ListBox.ItemTemplate>            <ListBox.Template>                <ControlTemplate>                    <StackPanel Background="Black" IsItemsHost="True" >                    </StackPanel>                </ControlTemplate>            </ListBox.Template>        </ListBox>    </ScrollViewer>唯一的問題是所選項目的右側(cè)有一個藍(lán)色框。我認(rèn)為可以更改選擇的顏色,但是找不到。
查看完整描述

3 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊

您需要使用ListBox.ItemContainerStyle。


ListBox.ItemTemplate指定應(yīng)如何顯示項目的內(nèi)容。但是WPF仍將每個項目包裝在ListBoxItem控件中,默認(rèn)情況下,如果選中它,則將其Background設(shè)置為系統(tǒng)突出顯示顏色。您不能停止WPF創(chuàng)建ListBoxItem控件,但是可以為它們設(shè)置樣式(在您的情況下,將Background設(shè)置為始終為Transparent或Black或其他顏色),并使用ItemContainerStyle。


juFo的答案顯示了一種可能的實現(xiàn)方式,即在項目樣式的上下文內(nèi)“劫持”系統(tǒng)背景畫筆資源;另一種可能更慣用的技術(shù)是對SetterBackground屬性使用。


查看完整回答
反對 回復(fù) 2019-11-29
?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊

<UserControl.Resources>

    <Style x:Key="myLBStyle" TargetType="{x:Type ListBoxItem}">

        <Style.Resources>

            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"

                             Color="Transparent"/>

        </Style.Resources>

    </Style>

</UserControl.Resources> 


<ListBox ItemsSource="{Binding Path=FirstNames}"

         ItemContainerStyle="{StaticResource myLBStyle}">  

您只需覆蓋listboxitem的樣式(請參閱:TargetType是ListBoxItem)


查看完整回答
反對 回復(fù) 2019-11-29
  • 3 回答
  • 0 關(guān)注
  • 1203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號