【发布时间】:2013-10-05 13:37:10
【问题描述】:
如何在我的 Lisview 中通过 Usercontrol 使用 DelegateCommand?在我的 Listview 中,我是这样使用它的:
<ListView x:Name="peopleListBox">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<UserControls:ItemTemplateControl QuestionText="{Binding parametr}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView>
我正在 UserControl 中尝试:
<Button Content="Click" Command="{Binding Path=DataContext.OpenCommand, ElementName=peopleListBox}"/>
还有这个:
<Button Content="Click" Command="{Binding Path=OpenCommand, ElementName=peopleListBox}"/>
这些代码都不起作用。
用户控制:
<UserControl
x:Class="App13.UserControls.ItemTemplateControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local1="using:App13"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Button Content="Click" Foreground="Black" Command="{Binding Path=DataContext.OpenCommand, ElementName=peopleListBox}"/>
</Grid>
</UserControl>
【问题讨论】:
-
为什么要在
DataTemplate中使用具有相同命令的按钮?该模板适用于所有项目。你想一遍又一遍地用相同的命令使用相同的按钮吗? -
你能提供
UserControl的代码吗? -
这只是一个示例,展示了我如何在列表视图中使用带有命令的按钮(不在用户控件中)
-
@meilke,这是我的代码
标签: c# xaml listview user-controls windows-store-apps