我正在将代码从Silverlight转换为WPF,但我希望应用程序稍后可以在两者中工作。所以我将silverlight文件链接到新的wpf项目。我将它转换为WPF项目时收到此错误:
错误1找不到静态成员' ThumbnailSourceProperty'在类型' CcsThumbnailDisplay'。 C:\ Users \ sahluwai \ Desktop \ cusControls2 \ leitch \ HarrisSilverlightToolkit \ Toolkit \ Source \ Controls \ DisplayControls \ Streaming \ Themes \ CcsThumbnailDisplay.xaml 22 109 DisplayControls
我的xaml代码是:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Harris.BCD.Toolkit.Silverlight.Controls">
<Style TargetType="local:CcsThumbnailDisplay">
<Setter Property="MinWidth" Value="40" />
<Setter Property="MinHeight" Value="30" />
<Setter Property="Background" Value="#FF000000"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CcsThumbnailDisplay">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border BorderBrush="#FF3C3C3C" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
BorderThickness="8"
Padding="0"
Grid.Row="0">
///////////////////////////////error line//////////////////////////////////////
//i am getting the error in this line below:
<Image HorizontalAlignment="Stretch" Source="{TemplateBinding ThumbnailSource}" Stretch="Uniform"/>
</Border>
<Border BorderBrush="#FF3C3C3C"
BorderThickness="1"
Padding="0"
Grid.Row="1">
<TextBlock Text="{TemplateBinding ChannelLabel}"
Foreground="White"
TextAlignment="Center"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的代码隐藏文件是:
namespace Harris.BCD.Toolkit.Silverlight.Controls
{
/// <summary>
/// Control: Video Image Display
///
/// Displays an thumbnail capture of a video given a video source
/// </summary>
public class CcsThumbnailDisplay : Control
{
#region Dependency Property Definitions
/// <summary>
/// ThumbnailSource Dependency Property
/// </summary>
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
"ThumbnailSource", typeof(ImageSource), typeof(CcsThumbnailDisplay),
new PropertyMetadata(null, new PropertyChangedCallback(CcsThumbnailDisplay.OnThumbnailSourcePropertyChanged)));
/// <summary>
/// ChannelLabel Dependency Property
/// </summary>
public static readonly DependencyProperty ChannelLabelProperty = DependencyProperty.Register(
"ChannelLabel", typeof(String), typeof(CcsThumbnailDisplay),
new PropertyMetadata("n/a", new PropertyChangedCallback(CcsThumbnailDisplay.OnChannelLabelPropertyChanged)));
#endregion
#region Data Properties
/// <summary>
/// The thumbnail source for the video stream
/// </summary>
public ImageSource ThumbnailSource
{
get { return (ImageSource)GetValue(CcsThumbnailDisplay.ImageSourceProperty); }
set { SetValue(CcsThumbnailDisplay.ImageSourceProperty, value); }
}
/// <summary>
/// The channel label for the video stream
/// </summary>
public String ChannelLabel
{
get { return (String)GetValue(CcsThumbnailDisplay.ChannelLabelProperty); }
set { SetValue(CcsThumbnailDisplay.ChannelLabelProperty, value); }
}
#endregion
#region Object Construction
/// <summary>
/// Constructs a thumbnial display Control
/// </summary>
public CcsThumbnailDisplay()
{
this.DefaultStyleKey = typeof(CcsThumbnailDisplay);
}
/// <summary>
/// Invoked when the template is applied
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
//this.Background = new ImageBrush()
//{
// ImageSource = this.ThumbnailSource,
// Stretch = Stretch.Fill
//};
}
#endregion
#region Control Event Handling
private void OnThumbnailSourceChanged(DependencyPropertyChangedEventArgs e)
{
//this.Background = new ImageBrush()
//{
// ImageSource = this.ThumbnailSource,
// Stretch = Stretch.Fill
//};
}
private void OnChannelLabelChanged(DependencyPropertyChangedEventArgs e)
{
}
#endregion
#region Static Property Dependency Handling
private static void OnThumbnailSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//CcsThumbnailDisplay objChange = d as CcsThumbnailDisplay;
//if (d == null)
// return;
//objChange.OnThumbnailSourceChanged(e);
}
private static void OnChannelLabelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//CcsThumbnailDisplay objChange = d as CcsThumbnailDisplay;
//if (d == null)
// return;
//objChange.OnChannelLabelChanged(e);
}
#endregion
}
}
答案 0 :(得分:2)
依赖项属性有命名约定。将ImageSourceProperty
重命名为ThumbnailSourceProperty
:
public static readonly DependencyProperty ThumbnailSourceProperty =
DependencyProperty.Register("ThumbnailSource", ...);
public ImageSource ThumbnailSource
{
get { return (ImageSource)GetValue(ThumbnailSourceProperty); }
set { SetValue(ThumbnailSourceProperty, value); }
}