WPF Designer and Dependency Binding Problem

I have a problem updating WPF Designer when binding to user dependency properties.

In the following example, I create a simple ellipse that I would like to populate with my MyAwesomeFill custom property. MyAwesomeFill has the default value of the yellow SolidColor brush.

The problem is that in the control form of the constructor I do not see the default fill of the ellipse (yellow), instead the ellipse is filled with SolidColor (# 00000000). However, when I run the application, everything works EXCELLENT.

Do you have any idea why this might happen?

Thanks.

Here is the code I'm using:

XAML:

<UserControl x:Class="TestApplication.MyEllipse"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300">
    <Grid>
        <Ellipse Stroke="Black" StrokeThickness="5" Fill="{Binding MyAwesomeFill}"></Ellipse>
    </Grid>
</UserControl>

FROM#:

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 TestApplication
{
    public partial class MyEllipse : UserControl
    {
        #region Dependency property MyAwesomeFill
        //Define and register dependency property
        public static readonly DependencyProperty MyAwesomeFillProperty = DependencyProperty.Register(
            "MyAwesomeFill",
            typeof(Brush),
            typeof(MyEllipse),
            new PropertyMetadata(new SolidColorBrush(Colors.Yellow), new PropertyChangedCallback(OnMyAwesomeFillChanged))
        );

        //property wrapper
        public Brush MyAwesomeFill
        {
            get { return (Brush)GetValue(MyAwesomeFillProperty); }
            set { SetValue(MyAwesomeFillProperty, value); }
        }

        //callback
        private static void OnMyAwesomeFillChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            MyEllipse m = (MyEllipse)obj;
            m.OnMyAwesomeFillChanged(e);
        }
        #endregion

        //callback
        protected virtual void OnMyAwesomeFillChanged(DependencyPropertyChangedEventArgs e)
        {
        }

        public MyEllipse()
        {
            InitializeComponent();

            DataContext = this;
        }

    }
}
+3
source share
1 answer

. MyEllipse , ( ), . , , .

, MyEllipse , .

<Ellipse 
    Stroke="Black" 
    StrokeThickness="5" 
    Fill="{Binding MyAwesomeFill, FallbackValue=Yellow}">
</Ellipse>
+3

Source: https://habr.com/ru/post/1708281/


All Articles