我如何在UserView中使用DelegateCommand在我的Lisview中?在我的列表視圖我使用它這樣:DelegateCommand與用戶控件列表視圖
<ListView x:Name="peopleListBox">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<UserControls:ItemTemplateControl QuestionText="{Binding parametr}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView>
我想,在用戶控件:
<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'中使用同一個命令的按鈕?該模板適用於所有項目。你是否想要一遍又一遍地使用同一個按鈕? – meilke
你可以提供'UserControl'的代碼嗎? – meilke
這只是一個示例,顯示如何在列表視圖中使用按鈕(不在usercontrol中) –