我正在构建一个Videoplayer自定义控件(项目名为WpfCustomControlLibrary1)并且想要添加一个加载命令。wpf命令自定义控件绑定xaml
这是我在我的课都加入到得到这个命令:
Public Class VideoPlayer
Inherits Control
...
Public Shared ReadOnly LoadCommad As RoutedUICommand
....
Shared Sub New()
'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
'This style is defined in Themes\Generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(GetType(VideoPlayer), New FrameworkPropertyMetadata(GetType(VideoPlayer)))
LoadCommad = New RoutedUICommand("Load", "Load Video", GetType(VideoPlayer))
CommandManager.RegisterClassCommandBinding(GetType(VideoPlayer), New CommandBinding(LoadCommad, AddressOf OnLoadExecuted))
End Sub
...
这也是我如何把它从我的XAML:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
.....
<Button Command="local:VideoPlayer.LoadCommand"
DockPanel.Dock="Right" Margin="0 5 5 0"
Width="30" HorizontalAlignment="Left"
Content="..." />
.....
但当我这个用户控件添加到一个新的项目是这样的:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bibli="clr-namespace:EigeneControllsBibli;assembly=EigeneControllsBibli"
xmlns:uc="clr-namespace:WpfCustomControlLibrary1;assembly=WpfCustomControlLibrary1"
Title="Window1" Height="442" Width="804">
<Grid>
<uc:VideoPlayer Source="C:\Users\Public\Videos\Sample Videos\Bear.wmv" Margin="0,106,369,0"></uc:VideoPlayer>
</Grid>
我得到一个错误,他不能将属性“命令”中的字符串转换为类型“System.Windows.Input.ICommand”的对象
有人看到出了什么问题吗?
感谢您的帮助, 尼科
是的,这是问题:D非常感谢你! :d – Nico 2009-12-15 09:03:17