簡體   English   中英

如何在Windows Phone中更改所選項目的背景顏色?

[英]How can I change selected item's background color in Windows Phone?

如何更改Windows Phone中具有數據模板的列表框中所選項目的背景顏色?

我已經知道可以使用Setter屬性。 我將在哪里寫它們?

謝謝。

<ListBox x:Name="listLocs" HorizontalAlignment="Left" Height="605" VerticalAlignment="Top" Width="250" SelectionChanged="listLocs_SelectionChanged" Margin="10,155,0,0" BorderBrush="#FF030042" BorderThickness="2" Foreground="#FF030042">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <StackPanel>
                    <Image Source="/Images/Pin2.png" Width="60"  Height="60" />
                </StackPanel>
                <StackPanel>
                    <StackPanel>
                        <TextBlock x:Name="txtName" Margin="10,0,0,0" Foreground="#FF030042"  FontSize="30" Text="{Binding Name}"/>
                    </StackPanel>
                    <StackPanel>
                        <TextBlock x:Name="txtDescription" Margin="10,0,0,0" Foreground="#FF030042" FontSize="20" Text="{Binding Description}"/>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

您可以在selectchanged事件處理程序中的完全后面的代碼中執行此操作:

    private void listLocs_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListBoxItem myitem = listLocs.SelectedItem as ListBoxItem;
       SolidColorBrush brush =  new SolidColorBrush(Color.FromArgb(255,255,0,0));
       myitem.Background = brush;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM