XAML을 사용하여 컨트롤의 절대 위치에 값을 바인딩하는 방법이 있습니까?XAML에서 컨트롤의 절대 위치에 값을 바인딩
나는 내 응용 프로그램에서 두 Button
사이에 그려야 할 Line
요소가 있습니다. 나는 Line
의 시작점을 Button
의 위치에 묶는 것이 어쨌든 RelativeSource
을 사용하여 일어나는 가장 쉬운 방법이라고 생각했습니다.
XAML을 사용하여 컨트롤의 절대 위치에 값을 바인딩하는 방법이 있습니까?XAML에서 컨트롤의 절대 위치에 값을 바인딩
나는 내 응용 프로그램에서 두 Button
사이에 그려야 할 Line
요소가 있습니다. 나는 Line
의 시작점을 Button
의 위치에 묶는 것이 어쨌든 RelativeSource
을 사용하여 일어나는 가장 쉬운 방법이라고 생각했습니다.
당신이 이런 걸 원하는 것 같다,
<UserControl x:Class="PracticeSample.MyButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Button x:Name="button" Content="Add" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<Line Stroke="Black" X1="0" Y1="0" HorizontalAlignment="Center" X2="{Binding ElementName=button, Path=ActualWidth}" Y2="{Binding ElementName=button, Path=ActualHeight}"/>
</Grid>
사용 버튼 대신에 페이지에서이 MyButton에를
편집 : 두 컨트롤 사이에 선을 그리려면 코드 샘플을 사용하지 마시고 페이지에서 직접 사용해보십시오.
<Canvas HorizontalAlignment="Left" Margin="10">
<Button x:Name="button2" Content="Add" Canvas.Left="10" Canvas.Top="5"/>
<Button Name="button" Content="Refresh Control" Canvas.Left="100" Canvas.Top="50"/>
<Line Stroke="Black" X1="{Binding Path=(Canvas.Left),ElementName=button2}" Y1="{Binding Path=(Canvas.Top), ElementName=button2}" X2="{Binding (Canvas.Left), ElementName=button}" Y2="{Binding (Canvas.Top), ElementName=button}"/>
</Canvas>
희망이 도움이됩니다!
원하는 위치에 Button과 Line이있는 템플릿을 정의한 다음 Button의 위치에서이 템플릿을 사용하십시오.
죄송합니다. 지정하지 않았습니다. 시작 지점과 종료 지점을 모두 바인딩하기 때문에 템플릿을 사용할 수 없습니다. 두 개의 임의의 요소 사이에 선을 그려야합니다. –
필자는 코드 숨김 파일에서 드로잉을 끝내기 때문에 요소의 모서리가 아닌 위치에 대한 계산을 수행 할 수있었습니다. –