显然,ItemContainerStyle并不存在于网格中,这就是问题所在。
我的程序有一个ListView,可以显示一堆项目。我想添加一个按钮到每个项目,提供更多的信息,这是我可以做的很容易。我遇到的问题是出现在每个项目上的边框,通过单击项目显示当前选择的用户来切换/关闭。我不希望这个边框包围我的按钮;我希望按钮放在边框的右边。
我不能将按钮放在单独的列表上,否则我会得到两个不同的可滚动列表,因此它必须保留在ListView中,但是ListView上的任何边框都将包围ListView中的所有内容。我的解决方案是用两个网格在StackPanel中创建一个ListView,其中第一个网格包含我所有的旧东西和可切换的边框,第二个网格只有我的按钮。所以现在我只需要把边界移到网格上..。但是怎么做呢?
XAML代码:
<!-- Other code up above... -->
<ListView x:Name="lstAvailableProjects"
Grid.Row="1"
ItemsSource="{Binding ProjectList, Mode=TwoWay}"
Height="Auto"
Width="Auto"
SelectionMode="Multiple"
IsRightTapEnabled="True"
IsDoubleTapEnabled="False"
IsSwipeEnabled="False"
SelectionChanged="lstAvailableProjects_SelectionChanged"
Background="Transparent"
VerticalAlignment="Top"
ItemContainerStyle="{StaticResource ActiveProjectListViewStyle}"
BorderThickness="30,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid HorizontalAlignment="Stretch" Width="250" Background="{Binding Converter={StaticResource projectStateColorConverter}}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding ProjectName}"
Foreground="Black"
Margin="10 5 0 0"
FontSize="17"
VerticalAlignment="Center"
Grid.Row="0"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding AssignmentRole}"
Visibility="{Binding ProjectAssignmentRole, Mode=OneWay, Converter={StaticResource visibilityConverter}}"
Foreground="Black"
Margin="10 3 0 5"
FontSize="14"
Grid.Row="1"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding StatusText}"
Foreground="Red"
Margin="10 3 0 5"
Grid.Row="2"
FontSize="14"/>
</Grid>
<Grid>
<Button>
<Button.Template>
<ControlTemplate>
<Image Source="../Assets/setting_icon.png" Height="40" />
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>发布于 2016-03-10 15:28:23
由于网格项是包装的,所以不能在xaml中进行更改以实现它,只能重写预付费容器。
一个小技巧就是将转换应用到按钮上。
<Button.RenderTransform>
<CompositeTransform TranslateX="100" TranslateY="100"/>
<Button.RenderTransform>https://stackoverflow.com/questions/35871668
复制相似问题