Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 面板wpf中图元的位置_C#_Wpf_Xaml - Fatal编程技术网

C# 面板wpf中图元的位置

C# 面板wpf中图元的位置,c#,wpf,xaml,C#,Wpf,Xaml,如何在堆栈面板中查找子元素的位置 <StackPanel Orientation="Horizontal"> <ToggleButton Width="20" Height="20" HorizontalAlignment="Stretch" VerticalAlignment

如何在堆栈面板中查找子元素的位置

        <StackPanel Orientation="Horizontal">
             <ToggleButton Width="20"
                           Height="20"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Stretch"
                           Visibility="Visible" />
             <TextBlock Margin="5"
                        VerticalAlignment="Center"
                        FontSize="15"
                        Text="Selection Mode" />
         </StackPanel>


如何找到切换按钮和文本块的X、Y位置?

基本上,控件的位置由保存它的控件、边距属性、对齐方式等决定


您可以使用它来确定子控件的位置。

基本上,控件的位置由保存它的控件、边距属性、对齐方式等决定

您可以使用它来确定子控件的位置。

您可以始终使用它将相对于一个UIElement的坐标转换为相对于另一个UIElement的坐标:

var toggleButtonPosition = toggleButton.TranslatePoint(new Point(0, 0), stackPanel);
var textBlockPosition = textBlock.TranslatePoint(new Point(0, 0), stackPanel);
上述代码将相对于相应控件的点(0,0)转换为相对于包含StackPanel的坐标,从而给出StackPanel内每个控件的位置。

您可以始终使用该代码将相对于一个UIElement的坐标转换为相对于另一个UIElement的坐标:

var toggleButtonPosition = toggleButton.TranslatePoint(new Point(0, 0), stackPanel);
var textBlockPosition = textBlock.TranslatePoint(new Point(0, 0), stackPanel);

上述代码将相对于相应控件的点(0,0)转换为相对于包含StackPanel的坐标,从而给出StackPanel内每个控件的位置。

@AndreasJohansson:与堆栈面板的关系。@AndreasJohansson:与堆栈面板的关系。