Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将未绑定的对象作为CommandParameter传递_C#_.net_Wpf_Xaml - Fatal编程技术网

C# 将未绑定的对象作为CommandParameter传递

C# 将未绑定的对象作为CommandParameter传递,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,是否有一种简单的方法可以在WPF中将类型为Color的对象作为CommandParameter传递 我有一个按钮列表,应该更改,例如我的应用程序的背景色 按钮看起来像: <Button Command={Binding SetBackgroundColor} CommandParameter={Color.Red} Background="Red" /> <Button Command={Binding SetBackgroundColor} CommandParameter=

是否有一种简单的方法可以在WPF中将类型为
Color
的对象作为
CommandParameter
传递

我有一个按钮列表,应该更改,例如我的应用程序的背景色

按钮看起来像:

<Button Command={Binding SetBackgroundColor} CommandParameter={Color.Red} Background="Red" />
<Button Command={Binding SetBackgroundColor} CommandParameter={Color.Green} Background="Green" />
<Button Command={Binding SetBackgroundColor} CommandParameter={Color.White} Background="White" />
<Button Command={Binding SetBackgroundColor} CommandParameter={???} Background="#FF00FF" />

点击彩色按钮,颜色就会改变

有什么想法、模式、最佳实践、方法或解决方法吗?

你可以写

<Button CommandParameter="{x:Static Colors.Red}" ... />


#FF00FF
或使用颜色资源:

<Window.Resources>
    <Color x:Key="myColor">#FF00FF</Color>
    ...
</Window.Resources>
...
<Button CommandParameter="{StaticResource myColor}" ... />

#FF00FF
...
...
你可以写

<Button CommandParameter="{x:Static Colors.Red}" ... />


#FF00FF
或使用颜色资源:

<Window.Resources>
    <Color x:Key="myColor">#FF00FF</Color>
    ...
</Window.Resources>
...
<Button CommandParameter="{StaticResource myColor}" ... />

#FF00FF
...
...

CommandParameter=“{x:Static Colors.Red}”
?Doh!对。这适用于“默认”
静态
颜色。但是,像
#FF00FF
这样传递颜色怎么样?是否有机会通过类似于
CommandParameter=“Color.FromRgb(255,0255)”
CommandParameter=“{x:Static Colors.Red}”
?Doh!对。这适用于“默认”
静态
颜色。但是,像
#FF00FF
这样传递颜色怎么样?是否有机会通过类似于
CommandParameter=“Color.FromRgb(255,0255)”
的程序?