0
显然,ItemContainerStyle在网格中不存在,这是问题所在。在网格上放置ItemContainerStyle
我的程序有一个ListView,显示一堆项目。我想为每个项目添加一个按钮,以提供更多信息,而且我可以轻松地做到这一点。我遇到的问题是出现在每个项目上的边框,通过单击该项目以显示当前选定的用户来打开/关闭该边框。我不希望这个边框包围我的按钮;我希望按钮位于边界右侧的位置。
我不能把按钮放在单独的列表中,或者我会得到两个不同的可滚动列表,所以它必须保留在ListView中,但ListView上的任何边框都将包围ListView中的所有内容。我的解决方案是在ListView中创建一个带有两个Grids的StackPanel,其中第一个Grid具有我所有的旧东西和可切换边框,第二个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>
这正是我所需要的。谢谢! –