1

いくつかのフィールドと削除ボタンを使用して UserControl を作成しました。リストボックスのDataTemplateで使用したいこのユーザーコントロール。

Window.xaml:

<ListBox ItemsSource="{Binding Users}">
   <ListBox.ItemTemplate>
     <DataTemplate>
       <WrapPanel>
          <my:User x:Name="user1" />
       </WrapPanel>
     </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

Listbox を含む Window の ViewModel で、Usercontrol の DeleteButton の ICommand を作成しました。

ユーザー コントロール.xaml:

<UserControl x:Name="ucUsers" .....>      
    <TextBlock Text="{Binding LastSeen}"  Width="140"/>
    <Button Content="Delete" 
            IsEnabled="{Binding CanUserDelete}" 
            Command="{Binding ElementName=ucUsers, Path=DataContext.DeleteCurrentUser}">
    </Button>

ViewModel の DeleteCurrentUser にアクセスできないのはなぜですか?

ポール

4

1 に答える 1

1
<Button Content="Delete" 
        IsEnabled="{Binding CanUserDelete}" 
        Command="{Binding  Path=DataContext.DeleteCurrentUser, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}">
于 2013-08-07T09:52:21.577 に答える