Challenge of changing the standard characteristic of WPF



  • We need to userControl to process a change in the height of the counterol. I mean, whatever happens when heightProperty changes. I do that.

        public new double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }
        public new static readonly DependencyProperty HeightProperty =
           DependencyProperty.Register(nameof(Height), typeof(double), typeof(MyControl), new PropertyMetadata(500.0, new PropertyChangedCallback(HeightChangedCallback)));
    
    private static void HeightChangedCallback(DependencyObject dependencyObject,
        DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
    {
    
        Console.WriteLine("its ok");
    }
    

    And it's kind of working, but in the end, it loses the possibility of an automatic height. How is it right to do that when standard properties need to be processed?



  • We need to userControl to process a change in the height of the counterol.

    We need to connect the processor to the SizeChanged event.

    <DataGrid x:Name="dg" />
    

    partial class MainWindow : Window {
      public MainWindow() {
         InitializeComponent();
         dg.SizeChanged += (s, e) => { 
            if (e.HeightChanged) 
               Console.WriteLine("its ok"); 
         };
      }
    } 
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2