我正在寻找一些有效隐藏继承成员的方法.我有一个继承自公共基类的类库.一些较新的后代类继承了依赖属性,这些属性已成为残留,在使用IntelliSense或在可视化设计器中使用类时可能会有点混乱.
这些类是为WPF或Silverlight 2.0编写的所有控件.我知道ICustomTypeDescriptor和ICustomPropertyProvider,但我很确定那些不能在Silverlight中使用.
它不是可用性问题的功能问题.我该怎么办?
更新
我真正想隐藏的一些属性来自不属于我自己的祖先,而且由于我正在设计的特定工具,我不能将成员隐藏在new操作员身上.(我知道,这太荒谬了)
这两者之间有什么区别,何时应该使用RegisterAttached()而不是.Register()?
只是一个简短的问题,澄清一些疑问.当元素绑定到依赖项属性时,是否运行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) 我有一个包含大量项目的大型解决方案.有些项目依赖于其他项目(尽管不是循环依赖项).
当我尝试删除项目的依赖项时,我收到一条错误消息,例如"项目系统添加了依赖项,无法删除".导致此错误的原因是什么?我怎么能解决这个问题?
依赖项属性的创建方式与属性相同.
是否仅在创建自定义控件时使用依赖项属性?
人们对INotifyPropertyChanged.PropertyChanged在视图模型中触发的简单.NET属性何时足够有任何指导?那么你什么时候想要升级到一个完整的依赖属性?或者DP主要用于观看?
我在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
我有一个非常简单的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.
我有问题,我不知道如何解决这个简单,我有很多这样的点,那么解决方案应该不复杂.
我有主要项目设置和主要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上设置.
我在控件上有一个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 ×8
c# ×4
silverlight ×3
.net ×1
binding ×1
data-binding ×1
polymorphism ×1
project ×1
setter ×1
xaml ×1