我试图AutomationProperties.Name在GroupStyle控件模板中设置控件的属性,它似乎什么也没产生.我把它设置Expander在我的模板中,但即使我只是放入一些没有绑定的文本,它也没有任何说明.我也试过把一个二传手放在上面GroupItem,但也没用.我有点失落.我希望小组项目上的属性可以解决它.
XAML:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication8.MainWindow"
x:Name="win"
Title="MainWindow"
Width="640"
Height="480">
<Grid x:Name="LayoutRoot">
<ListBox x:Name="lstbx"
Margin="71,45,99,78"
ItemsSource="{Binding ElementName=win,
Path=Samples}">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="AutomationProperties.Name"
Value="this is a test" />
<Setter Property="KeyboardNavigation.TabNavigation"
Value="Cycle" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Name="templateLstBxExpander"
AutomationProperties.Name="test test test"
IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<Label Name="templateLstBxExpanderHeader"
Content="{Binding Path=Name}"
FontWeight="Bold" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
XAML.cs: …
我想知道是否有人遇到过这种情况。基本上我想要做的是覆盖默认的 listviewitem 来自定义选定的背景/前景。我得到了一切正常和花花公子。问题是,我注意到在我实现网格视图的列表视图上,列被破坏了。我不确定是什么打破了这个。我覆盖默认样式的方法是使用混合通过编辑模板副本来获得完整样式。根据需要对其进行了修改。应用了它。这几乎就是它的样子。有什么想法吗?
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding" Value="2,0,0,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource CustomBorderBrush}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource CustomBackgroundBrush}" />
<Setter Property="Foreground" Value="{DynamicResource CustomForegroundBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions> …Run Code Online (Sandbox Code Playgroud) 所以我以前从未见过这个,我想弄清楚它的作用:
public static MyFunction operator +(MyObject first, MyObject second)
Run Code Online (Sandbox Code Playgroud)