tips on developing resolution independent application

前端 未结 4 2198
时光说笑
时光说笑 2020-12-04 12:59

Is it a good practice to find the workarea measurement and set some properties in code so that it could be bound to Control\'s margin or height/Width properties in xaml?

4条回答
  •  不思量自难忘°
    2020-12-04 13:09

    Small correction to the answer of Fredrik Hedblad:

    because you have set the DependencyProperty "Denominators" in the Grid element:

    
    
    

    you must call the GetDominator method using the grid. Instead of:

    private static void CalculateScale(Window window)
    {
        var denominators = GetDenominators(window);
    }
    

    you must use something like this:

    private static void mainElement_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        var mainElement = sender as FrameworkElement;
        var window = GetParentWindow(mainElement);
    
        CalculateScale(window, mainElement);
    }
    
    private static void CalculateScale(Window window, FrameworkElement mainElement)
    {
        var denominators = GetDenominators(mainElement);
    }
    

提交回复
热议问题