- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想要一个按钮来显示这样的应用程序设置窗口:
<Window.Resources>
<local:SettingsWindow x:Key="SettingsWnd"/>
</Window.Resources>
<Window.DataContext>
<local:MyViewModel/>
</Window.DataContext>
<Button Command="{Binding ShowSettingsCommand}"
CommandParameter="{DynamicResource SettingsWnd}"/>
ViewModel 有点像:
class MyViewModel : BindableBase
{
public MyViewModel()
{
ShowSettingsCommand = new DelegateCommand<Window>(
w => w.ShowDialog());
}
public ICommand ShowSettingsCommand
{
get;
private set;
}
}
问题是它只能工作一次,因为您无法重新打开之前关闭的窗口。显然,上面的 XAML 不会创建像那样打开的新实例。
有没有办法在每次调用命令时将新窗口作为 CommandParameter
传递?
最佳答案
这个转换器能解决您的问题吗?
class InstanceFactoryConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var type = value.GetType();
return Activator.CreateInstance(type);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
...
<Window.Resources>
<local:SettingsWindow x:Key="SettingsWnd"/>
<local:InstanceFactoryConverter x:Key="InstanceFactoryConverter"/>
</Window.Resources>
...
<Button Command="{Binding ShowSettingsCommand}"
CommandParameter="{Binding Source={StaticResource SettingsWnd}, Converter={StaticResource InstanceFactoryConverter}}"/>
关于c# - 每次都将新窗口作为 CommandParameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31950480/
我们有一个使用 VS 2015 编写的 WPF 应用程序。该应用程序在整个应用程序的多个位置都有一个错误图标,用户可以使用它来报告错误。它会启动他们的电子邮件客户端向我们的帮助票务系统发送电子邮件。
我想要一个按钮来显示这样的应用程序设置窗口: ViewModel 有点像: class MyViewModel : BindableBase { public M
如何将我当前所在的窗口作为参数传递给命令? 我喜欢在 XAML 标记中这样做: 最佳答案 在我的情况下,提供的答案都没有奏效。 这对我有用: 关于wpf - 将当前窗口作为 CommandP
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question
我正在尝试通过 CommandParameter 传递 UserName。
我正在尝试将 ViewModel 中的变量作为参数发送到命令。命令看起来像这样: public class EditPersonCommand : ICommand { private bool
我在我的 WPF 应用程序中使用 MVVM Light。 我创建了一个类 RedirectToUriCommandArgument.cs。 public class RedirectToUriComm
我正在尝试在 WPF 应用程序中将 Command 和 CommandParameter 绑定(bind)与按钮一起使用。我有这个完全相同的代码在 Silverlight 中工作得很好,所以我想知道我
是否可以有不同的 Datacontext对于 WPF Command和一个 CommandParameter ?
我有一个从 ItemsSource 创建的树 View 的 SecondViewModel实例,与我的 Window DataContext 不同。 我想通过`CommandParameter 发送属
如何通过True到 CommandParameter ? 目前我正在强制添加 Boolean.True到资源字典,但这似乎是一种笨拙的方法。 最佳答案 由于命令参数属于“对象”类型,因此 XAML 解
我有一个带有“MainView”和一些嵌套 View 的 Catel 应用程序。 嵌套 View 具有 ListView一些项目有 ContextMenu与一些 MenuItems . 在 MainV
我想得到 NamePlaylist的Item我点击一个MenuContext。但是参数总是空的,我不知道为什么。 这是 ListView 中的菜单 XML
是否可以在多重绑定(bind)中使用 CommandParameter="{Binding}"? 我正在尝试在数据网格中执行此操作。
我正在使用来自 AlexeyZakharov's weblog 的类 InvokeDelegateCommandAction根据一些人的建议,这是将参数从 View 发送回 EventTrigger
我通过 Google 和 StackOverflow 进行了很多搜索,但没有任何答案可以解决我的问题。 我有两个 Xaml 文件: MainWindow.xaml
也许这是一个愚蠢的问题,但我找不到答案:在下面的 xaml 中 CommandParameter 是什么?绑定(bind)到?或者一般来说,"{Binding}" 是什么意思?意思是? 最佳答案 {
我想通过xaml中的commandparameter将多个参数传递给命令。 在上面的示例中,我想将其他变量传递给 ID 变量旁边的命令。我怎样才能实现它?非常感谢。 最佳答案 您可以将MultiBi
我有以下 XAML: 当 GridPrintCommand 执行时,其传
我想在我的类 CommandProvider 中实现 CommandParameter,它用于命令(按钮等)并继承自 ICommand,但我不明白如何实现它。示例: XAML
我是一名优秀的程序员,十分优秀!