|
WPF custom control
|
|||
---|---|---|---|
#18+
Есть класс с несколькими свойствами FieldOptions, который должен влиять на некоторые свойства родителя. Нужно для нескольких стандартных контролов типа TextEdit, ButtonEdit добавить этот класс в виде расширения функциональности. Не могу понять как FieldOptions будет знать родителя. Пример: public class FieldOptions : DependencyObject { private static readonly Brush mandatoryBackground = new SolidColorBrush(Colors.Yellow); private static readonly Brush readonlyBackground = new SolidColorBrush(Colors.Silver); public static readonly DependencyProperty MandatoryProperty; public static readonly DependencyProperty ReadOnlyProperty; static AptFieldOptions() { Type owner = typeof(FieldOptions); MandatoryProperty = DependencyProperty.Register("Mandatory", typeof(bool), owner, new UIPropertyMetadata(true, new PropertyChangedCallback(mandatoryChangedCallback))); ReadOnlyProperty = DependencyProperty.Register("ReadOnly", typeof(bool), owner, new UIPropertyMetadata(false)); } public bool Mandatory { get { return (bool)GetValue(MandatoryProperty); } set { SetValue(MandatoryProperty, value); } } public bool ReadOnly { get { return (bool)GetValue(ReadOnlyProperty); } set { SetValue(ReadOnlyProperty, value); } } private static void mandatoryChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { // Как здесь для CustomTextEdit изменить свойство??? } } public class CustomTextEdit : TextEdit { public static readonly DependencyProperty FieldOptionsProperty; static CustomTextEdit() { Type owner = typeof(CustomTextEdit); AptFieldOptionsProperty = DependencyProperty.Register("FieldOptions", typeof(FieldOptions), owner, new PropertyMetadata(null, new PropertyChangedCallback(FieldOptionsChangedCallback))); } private static void FieldOptionsChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { // } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public FieldOptions FieldOptions { get { return (FieldOptions)GetValue(FieldOptionsProperty); } set { SetValue(CustomTextEdit.FieldOptionsProperty, value); } } } ... |
|||
:
Нравится:
Не нравится:
|
|||
11.02.2013, 12:28 |
|
WPF custom control
|
|||
---|---|---|---|
#18+
Возможно я не правильный вопрос вообще задал и пытаюсь изобрести велосипед. Попытаюсь объяснить заново. Итак, мне нужно расширить функциональность нескольких контролов. Хочу написать класс со свойствами зависимости. Потом этот класс сделать как свойство зависимости в контроле. Итого получается: Options |_ Property1 |_ Property2 |_ Property3 |_ Property4 Control1 |_ Options |_ Property1 |_ Property2 |_ Property3 |_ Property4 Нужно сделать так, что бы при изменении свойства 1 в классе Options что-то делалось с контролом Control1, где Options объявлен. Проблема в том, что не могу получить доступ к Control1 из Options. ... |
|||
:
Нравится:
Не нравится:
|
|||
11.02.2013, 19:05 |
|
WPF custom control
|
|||
---|---|---|---|
#18+
см Attached Properties ... |
|||
:
Нравится:
Не нравится:
|
|||
12.02.2013, 01:02 |
|
|
start [/forum/topic.php?fid=21&fpage=32&tid=1441493]: |
0ms |
get settings: |
10ms |
get forum list: |
12ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
44ms |
get topic data: |
12ms |
get forum data: |
3ms |
get page messages: |
42ms |
get tp. blocked users: |
1ms |
others: | 296ms |
total: | 428ms |
0 / 0 |