using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace Client
{
    /// <summary>
    /// Interaction logic for UcEditDate.xaml
    /// </summary>
    ///
    public partial class UcEditDate : System.Windows.Controls.UserControl
    {
        #region DateText
        /// <summary>
        /// 获取DateText标识
        /// </summary>
        public static readonly DependencyPropertyKey DateTextPropertyKey = 
            DependencyProperty.RegisterReadOnly(
            "DateText", 
            typeof(string), 
            typeof(UcEditDate), 
            new FrameworkPropertyMetadata(""));
        /// <summary>
        /// 获取DateText属性
        /// </summary>
        public static readonly DependencyProperty DateTextProperty = DateTextPropertyKey.DependencyProperty;
        /// <summary>
        /// 获取DateText
        /// </summary>
        /// 
        public string DateText {
            get { return (string)GetValue(DateTextProperty); }
            set { SetValue(DateTextProperty, value); }
        }        #endregion        public UcEditDate()
        {
            InitializeComponent();
        }
}当wpf中使用DateText="{Binding Path=ServerEndDateFormatStr}" 时,提示DateText不是DependencyProperty  是Property ,不能使用绑定

解决方案 »

  1.   

    Mark,实在不知道DateText是否可写
      

  2.   

    UserControl是安全控件,必须输入
      

  3.   

    http://msdn.microsoft.com/msdnmag/issues/07/05/WPF/default.aspx?loc=zh
    中也有UserControl,跟我代码差不多,但可以绑定public partial class PlayButton : System.Windows.Controls.UserControl
    {
      ...
      public static readonly DependencyProperty MediaPlayerProperty =
        DependencyProperty.Register(
          “MediaPlayer”, typeof(MediaElement), typeof(PlayButton));  // The ID of the Media Element that the button is tied to.
      public MediaElement MediaPlayer
      {
        get { return (MediaElement)GetValue(MediaPlayerProperty); }
        set { SetValue(MediaPlayerProperty, value); }
      }
    }
    <!-- MainWindow.xaml -->
    <Window x:Class=”Tester.MainWindow”
        xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
        xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
        xmlns:cust=”clr-namespace:CustomWPF;assembly=CustomWPF”
        Title=”Control Viewer” 
        Height=”100” Width=”200”>
      <StackPanel>    <MediaElement Width=”150” Height=”100” 
             Name=”theMedia” 
             Source=”http://download.microsoft.com/.../ctorrec9billg.wmv”
             LoadedBehavior=”Manual” />    <TextBlock>User Control:</TextBlock>    <cust:PlayButton MediaPlayer=”{Binding ElementName=theMedia}” />  这句MediaPlayer可以绑定  </StackPanel>
    </Window>
      

  4.   

    http://topic.csdn.net/u/20071119/17/85826233-bb20-4ea5-9c77-210757348186.html
    再+100分