【问题标题】:Cannot find the static member 'ThumbnailSourceProperty' on the type 'CcsThumbnailDisplay'在“CcsThumbnailDisplay”类型上找不到静态成员“ThumbnailSourceProperty”
【发布时间】:2015-11-09 22:36:00
【问题描述】:

我正在将代码从 Silverlight 转换为 WPF,但我希望该应用程序稍后可以同时在这两种情况下工作。所以我将 Silverlight 文件链接到新的 wpf 项目。将其转换为 WPF 项目时出现此错误:

错误 1 ​​在类型“CcsThumbnailDisplay”上找不到静态成员“ThumbnailSourceProperty”。 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
}

}

【问题讨论】:

    标签: c# wpf xaml silverlight


    【解决方案1】:

    依赖属性有命名约定。将ImageSourceProperty 重命名为ThumbnailSourceProperty

    public static readonly DependencyProperty ThumbnailSourceProperty =
        DependencyProperty.Register(nameof(ThumbnailSource), ...); 
    
    public ImageSource ThumbnailSource
    {
        get { return (ImageSource)GetValue(ThumbnailSourceProperty); }
        set { SetValue(ThumbnailSourceProperty, value); }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-16
      • 2015-08-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多