próbuję stworzyć dependency property. gdy wszystko było wewnątrz klasy MainWindow, to wszystko działało, przy próbie przeniesienia obiektów do zewnętrznej klasy, przeniesiona część przestała działać. próbowałem to naprawić na różne sposoby i teraz mam coś takiego
kod:

<Button Name="btn" BorderBrush="Red" Content="{Binding ElementName=MyWindow, Path=MySetText}" 
BorderThickness="{Binding ElementName=MyWindow,  Path=myMargin.MyMargin}"  
Width="100" Height="20" Click="clickChangeText" Margin="347,222,346.6,178">
</Button>
public class MyDerpProperties : UIElement//DependencyObject// INotifyPropertyChanged
    {
        static FrameworkPropertyMetadata MarginMetadata;

        public Thickness MyMargin
        {
            get { return (Thickness)GetValue(MyMarginProperty); }
            set { SetValue(MyMarginProperty, value);  }
        }

        public static readonly DependencyProperty MyMarginProperty;



        static MyDerpProperties()
        {
            MarginMetadata = new FrameworkPropertyMetadata(
              new Thickness(3),
              FrameworkPropertyMetadataOptions.AffectsMeasure//,
                                                             //new PropertyChangedCallback(Margin_propertyChanged),
                                                             //new CoerceValueCallback(Margin_coerceValue)
              );

            MyMarginProperty =
            DependencyProperty.Register(
                "MyMargin", typeof(Thickness),
                typeof(MyDerpProperties), MarginMetadata//,
                                                        //isMarginValid
                );

        }

}

public partial class MainWindow : Window
    {
private MyDerpProperties myMargin;
        
       /* public MyDerpProperties MyMargin
        {
            get { return myMargin; }
            set { myMargin = value; }

        }*/    
 
        public MainWindow()
        {
            
            InitializeComponent();
            myMargin = new MyDerpProperties();
            //DataContext = myMargin;
            //
        }

private void clickChangeText(object sender, RoutedEventArgs e)
        {
            SetValue(CounterProperty, Counter + 1);
            SetValue(MySetTextProperty, name + Counter.ToString());
          
            SetValue(MyDerpProperties.MyMarginProperty, new Thickness(Counter));
          
        }
}