【发布时间】:2016-03-08 15:39:42
【问题描述】:
显然 ItemContainerStyle 不存在于 Grid 中,这就是问题所在。
我的程序有一个显示一堆项目的 ListView。我想为每个项目添加一个按钮,以提供更多信息,而我可以轻松做到这一点。我遇到的问题是出现在每个项目上的边框,通过单击项目来打开/关闭它以显示当前选择的用户。我不希望这个边框包围我的按钮;我想把按钮放在有边框的位的右边。
我不能将按钮放在单独的列表中,否则我会得到两个不同的可滚动列表,因此它必须保留在 ListView 内,但 ListView 上的任何边框都会包围 ListView 中的所有内容。我的解决方案是在 ListView 内制作一个带有两个 Grid 的 StackPanel,其中第一个 Grid 有我所有的旧东西和可切换的边框,而第二个网格只有我的按钮。所以现在我只需要将边框移到网格上...但是如何?
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>
【问题讨论】:
标签: winrt-xaml