相关疑难解决方法(0)

TreeView显示所选项目的蓝色

我有一个树视图结构.当我尝试单击节点时,会出现一种蓝色,显示所选节点.我怎么能删除它.我不希望在树上显示选择颜色.

wpf xaml

25
推荐指数
1
解决办法
2万
查看次数

WPF ListBox图像选择了传奇继续

好吧,在我的ListBox滚动图像w /文本等等saga继续.当我单击其中一个项目以选择它时,它会运行一个过程来打开Web浏览器并转到特定的URL.我现在遇到的问题是,当WPF应用程序失去焦点,并且Web浏览器打开时,在列表框内单击的项目将变为白色.这是整个ListBox XAML.我已将所选项目设置为透明,这是否与WPF应用程序失去焦点有关?

有什么我可以添加运行该过程的代码来打开Web浏览器以将焦点设置回WPF应用程序?

谢谢.

   <ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Margin="61,-8,68,-18" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" Background="Transparent" BorderThickness="0">
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
                <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
                <Setter Property="Padding" Value="20,10,20,10" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border x:Name="Bd" SnapsToDevicePixels="true" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter Property="Background" TargetName="Bd" …
Run Code Online (Sandbox Code Playgroud)

wpf listbox focus image selected

8
推荐指数
1
解决办法
8335
查看次数

TreeView.IsSelected触发器无法正常工作

我试图在TreeView中更改SelectedItem模板.我按照描述在Style.Triggers中编写了简单的容器样式并更改了项目模板

[1]:如何使用某种颜色突出显示树视图所选项目?要么

[2]:WPF TreeView:如何设置带有圆角的选定项目,如在资源管理器中,但它不起作用.

然后我创建了一个新项目,并使用简单的样式和模板创建了TreeView

<TreeView>
        <TreeViewItem Header="Item1" />
        <TreeViewItem Header="Item2" />
        <TreeViewItem Header="Item3"/>

        <TreeView.Resources>
            <DataTemplate DataType="{x:Type TreeViewItem}" x:Key="selectedTemplate">
                <StackPanel Height="25">
                    <TextBlock Text="SelectedItem"/>
                </StackPanel>
            </DataTemplate>
        </TreeView.Resources>

        <TreeView.ItemContainerStyle>
            <Style TargetType="TreeViewItem">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold"/>
                        <Setter Property="FontStyle" Value="Italic"/>
                        <Setter Property="Foreground" Value="Red"/>
                        <Setter Property="Background" Value="Green"/>
                        <Setter Property="ItemTemplate" Value="{StaticResource selectedTemplate}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
Run Code Online (Sandbox Code Playgroud)

所以,然后我在树视图中选择了TreeViewItem,FontWeight,FontStyle和Foreground都被更改了,但是Background和ItemTemplate没有改变.

结果: 这里

你能解释这个奇怪的行为吗?

wpf treeview triggers itemtemplate

2
推荐指数
1
解决办法
5408
查看次数

标签 统计

wpf ×3

focus ×1

image ×1

itemtemplate ×1

listbox ×1

selected ×1

treeview ×1

triggers ×1

xaml ×1