'提供帮助'。当按下编辑按钮时,我需要从视图模型调用另一个视图。 showdailog()我不能再使用了。我从这个视图中调用另一个子视图。请帮忙
编辑 - > 删除< /按钮> < /边框> < /边框> < /边框> < /边框> < /边框> < /边框> < /边框> - >
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
<Button Command ="{Binding SubmitCommand}" Name="Submit" Content="Search" HorizontalAlignment="Left" Margin="349,45,0,0" VerticalAlignment="Top" Width="75"/>
<Button Command ="{Binding CloseCommand}" Name="Close" Content="Close" HorizontalAlignment="Left" Margin="535,379,0,0" VerticalAlignment="Top" Width="75"/>
<Button Command ="{Binding ReLoadCommand}" Name="Reload" Content="ReLoad" HorizontalAlignment="Left" Margin="535,45,0,0" VerticalAlignment="Top" Width="75"/>
<Button Command ="{Binding ClearCommand}" Name="Clear" Content="CLear" HorizontalAlignment="Left" Margin="443,45,0,0" VerticalAlignment="Top" Width="75"/>
<Label x:Name="label" Content="Enter First Name or Last Name for Search" HorizontalAlignment="Left" Margin="84,18,0,0" VerticalAlignment="Top"/>
<ComboBox ItemsSource="{Binding SelectedYear}" Name="comboBox" HorizontalAlignment="Left"
Margin="10,379,0,0" VerticalAlignment="Top" Width="120" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding Item}">
<!--SelectedItem="{Binding Item} -->
</ComboBox>
</Grid>
视图模型:
private ICommand _editRowData;
public ICommand EditRowData
{
get { return _editRowData ?? (_editRowData = new CommandHandler(() => RowDataAction(), _canExecute)); }
}
private SecondWindowViewModel childView;
public void RowDataAction()
{
childView = new SecondWindowViewModel();
//MessageBox.Show("Edit Button Pressed");
SecondWindow view = new SecondWindow()
{
DataContext = childView
};
childView.Labelcontent = "kala";
view.ShowDailog();
//view.ShowDailog() is giving me error. Please explain and provide me solve.
答案 0 :(得分:0)
将按钮绑定更改为:
<Button Command="{Binding Path=DataContext.EditRowData, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}" ... etc