标签: dependency-properties

隐藏继承的成员

我正在寻找一些有效隐藏继承成员的方法.我有一个继承自公共基类的类库.一些较新的后代类继承了依赖属性,这些属性已成为残留,在使用IntelliSense或在可视化设计器中使用类时可能会有点混乱.

这些类是为WPF或Silverlight 2.0编写的所有控件.我知道ICustomTypeDescriptorICustomPropertyProvider,但我很确定那些不能在Silverlight中使用.

它不是可用性问题的功能问题.我该怎么办?

更新

我真正想隐藏的一些属性来自不属于我自己的祖先,而且由于我正在设计的特定工具,我不能将成员隐藏在new操作员身上.(我知道,这太荒谬了)

c# polymorphism silverlight wpf dependency-properties

40
推荐指数
6
解决办法
2万
查看次数

DependencyProperty.Register()或.RegisterAttached()

这两者之间有什么区别,何时应该使用RegisterAttached()而不是.Register()?

wpf dependency-properties workflow-foundation

39
推荐指数
3
解决办法
2万
查看次数

Setter不在依赖属性上运行?

只是一个简短的问题,澄清一些疑问.当元素绑定到依赖项属性时,是否运行setter?

public string TextContent
{
    get { return (string)GetValue(TextContentProperty); }
    set { SetValue(TextContentProperty, value); Debug.WriteLine("Setting value of TextContent: " + value); }
}

public static readonly DependencyProperty TextContentProperty =
    DependencyProperty.Register("TextContent", typeof(string), typeof(MarkdownEditor), new UIPropertyMetadata(""));
Run Code Online (Sandbox Code Playgroud)

...

<TextBox Text="{Binding TextContent}" />
Run Code Online (Sandbox Code Playgroud)

正如我注意到我的setter中的下面没有运行

Debug.WriteLine("Setting value of TextContent: " + value);
Run Code Online (Sandbox Code Playgroud)

wpf setter dependency-properties

37
推荐指数
2
解决办法
1万
查看次数

在VS2010中删除项目依赖项时出错

我有一个包含大量项目的大型解决方案.有些项目依赖于其他项目(尽管不是循环依赖项).

当我尝试删除项目的依赖项时,我收到一条错误消息,例如"项目系统添加了依赖项,无法删除".导致此错误的原因是什么?我怎么能解决这个问题?

dependency-properties project visual-studio-2010

37
推荐指数
3
解决办法
2万
查看次数

Property和Dependency Property之间有什么区别

依赖项属性的创建方式与属性相同.

是否仅在创建自定义控件时使用依赖项属性?

c# silverlight wpf dependency-properties

36
推荐指数
3
解决办法
2万
查看次数

何时使用WPF依赖属性与INotifyPropertyChanged

人们对INotifyPropertyChanged.PropertyChanged在视图模型中触发的简单.NET属性何时足够有任何指导?那么你什么时候想要升级到一个完整的依赖属性?或者DP主要用于观看?

wpf binding dependency-properties inotifypropertychanged

35
推荐指数
2
解决办法
1万
查看次数

如何使用样式中的附加属性?

我在ButtonStyle中创建了一个Image.现在我创建了一个附加属性,以便我可以为该图像设置Source.应该是直截了当但我坚持下去.

这是我缩短的ButtonStyle:

<Style x:Key="ToolBarButtonStyle"
        TargetType="Button">
    ...
    <Image x:Name="toolbarImage"
            Source="{TemplateBinding PrismExt:ImageSourceAttachable:ImageSource}"
            Width="48"
            Height="48" />
    ...
</Style>
Run Code Online (Sandbox Code Playgroud)

这是附加的属性定义,注意我不知道如何修复回调,因为dependencyproperty似乎是按钮而不是图像.而Button不会在我的风格中暴露我的Image.这很棘手.

namespace SalesContactManagement.Infrastructure.PrismExt
{
    public class ImgSourceAttachable
    {
        public static void SetImgSource(DependencyObject obj, string imgSource)
        {
            obj.SetValue(ImgSourceProperty, imgSource);
        }

        public static string GetImgSource(DependencyObject obj)
        {
            return obj.GetValue(ImgSourceProperty).ToString();
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImgSourceProperty =
            DependencyProperty.RegisterAttached("ImgSource", typeof(string), typeof(ImgSourceAttachable), new PropertyMetadata(Callback));

        private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //((Button)d).Source = …
Run Code Online (Sandbox Code Playgroud)

.net silverlight wpf dependency-properties attached-properties

35
推荐指数
1
解决办法
2万
查看次数

为什么在MultiBinding中转换值时会得到DependencyProperty.UnsetValue?

我有一个非常简单的IMultiValueConverter,它只是OR的两个值.在下面的示例中,我想使用同样简单的布尔型逆变器反转第一个值.

<MultiBinding Converter="{StaticResource multiBoolToVis}">
    <Binding Path="ConditionA" Converter="{StaticResource boolInverter}"/>
    <Binding Path="ConditionB"/>
</MultiBinding>
Run Code Online (Sandbox Code Playgroud)

和逆变器:

public class BoolInverterConverter : IValueConverter
{
    #region IValueConverter Members
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is bool)
        {
            return !((bool)value);
        }
        return null;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    #endregion
}
Run Code Online (Sandbox Code Playgroud)

当我包含boolInverter时,MultiValueConverter中的第一个值变为"DependencyProperty.UnsetValue".当我不使用转换器时没有问题(当然,除了我不是针对的逻辑).

我错过了什么吗?单步执行调试器会显示InverseBoolConverter正在反转我传递的值,但该值不会被"发送"到MultiValueConverter.

c# wpf xaml dependency-properties ivalueconverter

28
推荐指数
2
解决办法
3万
查看次数

如何简单地将其绑定到ConverterParameter?

我有问题,我不知道如何解决这个简单,我有很多这样的点,那么解决方案应该不复杂.

我有主要项目设置和主要XAML.

我有Binding Converter和XAML文件的依赖项目看起来像:

<TextBlock Text="{Binding X.Y.Z, 
                 Converter={StaticResource ProbabilityConverter},                 
                 ConverterParameter=??????????????, Mode=OneWay}"
 />
Run Code Online (Sandbox Code Playgroud)

此XAML文件由主项目的主XAML文件加载.

我必须将一个属性的值从Setting's传递给ConverterParameter,此参数可以在运行时更改,那么这必须是Binding,Binding我只能DependencyProperty在这种情况下做.

我必须DependencyProperty为此Setting属性做包装才能解决这个问题?

当我尝试设置时Binding,ConverterParameter我将在运行时获得此异常:

无法在"绑定"类型的"ConverterParameter"属性上设置"绑定".'绑定'只能在DependencyObject的DependencyProperty上设置.

c# data-binding dependency-properties

24
推荐指数
2
解决办法
3万
查看次数

删除集合中的项目时,ObservableCollection依赖项属性不会更新

我在控件上有一个ObservableCollection类型的附加属性.如果我在集合中添加或删除项目,则ui不会更新.但是,如果我用新的替换集合,则ui会更新ViewModel.

有人能给我一个我在Dependency对象中需要做什么的例子,以便它可以处理集合中的变化吗?

下面列出了依赖项对象的一部分:

public class RadCalendarBehavior : DependencyObject
{
private static void OnSpecialDaysChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
  var calendar = d as RadCalendar;
  if (e.NewValue != null)
  {
    calendar.DayTemplateSelector = new SpecialDaySelector((ObservableCollection<DateTime>)e.NewValue, GetSpecialDayTemplate(d));
  }
}

public static ObservableCollection<DateTime> GetSpecialDays(DependencyObject obj)
{
  return (ObservableCollection<DateTime>)obj.GetValue(SpecialDaysProperty);
}

public static void SetSpecialDays(DependencyObject obj, ObservableCollection<DateTime> value)
{
  obj.SetValue(SpecialDaysProperty, value);
}

public static readonly DependencyProperty SpecialDaysProperty =
    DependencyProperty.RegisterAttached("SpecialDays", typeof(ObservableCollection<DateTime>), typeof(RadCalendarBehavior), new UIPropertyMetadata(null, OnSpecialDaysChanged));
}
}
Run Code Online (Sandbox Code Playgroud)

我知道我需要注册该集合已经更改,但我不确定如何在依赖项属性中执行此操作

wpf dependency-properties observablecollection

23
推荐指数
3
解决办法
1万
查看次数