【发布时间】:2016-09-26 01:36:55
【问题描述】:
我在我的 ActionBar 自定义控件中创建了一个依赖属性:
public NavigationStyle NavigationStyle
{
get { return (NavigationStyle)GetValue(NavigationStyleProperty); }
set { SetValue(NavigationStyleProperty, value); }
}
// Using a DependencyProperty as the backing store for NavigationStyle. This enables animation, styling, binding, etc...
public static readonly DependencyProperty NavigationStyleProperty =
DependencyProperty.Register("NavigationStyle", typeof(NavigationStyle), typeof(ActionBar), new
NavigationStylePropertyMetadata(NavigationStyle.TwoColumnsNavigation));
public enum NavigationStyle
{
SingleNavigation,
TwoColumnsNavigation
}
我有一个回调,当该属性的值发生变化时,我必须编辑 ActionBar 样式(宽度):
private class NavigationStylePropertyMetadata : FrameworkPropertyMetadata
{
public NavigationStylePropertyMetadata(object defaultValue)
:base(defaultValue)
{
base.PropertyChangedCallback = (dependicyProperty, e) => {
// How can i get the instance of the ActionBar control ?
switch ((NavigationStyle)e.NewValue)
{
case NavigationStyle.SingleNavigation:
// here i need to edit the width of the ActionBar to 500px
break;
case NavigationStyle.TwoColumnsNavigation:
// and here i have to edit the ActionBar width to 700
break;
default:
break;
}
};
}
}
但我的问题是,我怎样才能在PropertyChangeCallback 中获取 ActionBar Control(inherits from flyout) 的实例来编辑其样式?
【问题讨论】:
-
这是您的
dependicyProperty参数。将其投射到 ActionBar。 -
@Clemens 属性
DependencyObjectType?
标签: c# wpf dependency-properties