의 크기에 자식 개체 :WPF 구속 캔버스의 크기 조정 '다음 XAML을 감안할 때 캔버스
<Window x:Class="AdornerTesting.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="500" Width="500"
Loaded="Window_Loaded">
<Grid Name="grid">
<Canvas Name="canvas" Width="400" Height="400" Background="LightGoldenrodYellow">
<RichTextBox Name="richTextBox" Canvas.Top="10" Canvas.Left="10" BorderBrush="Black" BorderThickness="2"
Width="200"
Height="200"
MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}},Path=ActualWidth}"
MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}},Path=ActualHeight}"/>
</Canvas>
</Grid>
</Window>
및 adorners의 집합과 같이로드 된 이벤트의를 RichTextBox에 추가 :
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(richTextBox);
adornerLayer.Add(new ResizeAdorner(richTextBox));
RichTextBox의 크기를 Canvas의 가시 범위 이상으로 유지하지 못하게하려면 어떻게해야합니까?
ResizeAdorner는 MSDN adorner 예제에서 찾을 수있는 코드와 기본적으로 동일하며 정상적으로 작동합니다. RichTextBox의 크기를 조정할 수있는 방법을 계산하기 위해 코드 숨김에서 MaxWidth 및 MaxHeight의 바인딩을 사용하여 작업해야합니까? 또는 XAML에서이 작업을 수행 할 수있는 방법이 있습니까?
예, 즉 캔버스가 아닌하여 RichTextBox,해야한다, 캔바에 0 개 캔버스의 가장자리를 지나치게 오른쪽과 아래쪽으로 드래그를 고정시킵니다. 내가 겪고있는 문제와 원래 질문에서 언급하지 못한 것은 왼쪽과 위로 크기를 조정하고있었습니다. 내가 어떻게 초기 질문에 그것을 넣지 않았는지 모르지만 나는하지 않았다. 그것은 비난 할 방향으로 내 크기 조정 코드였습니다. XAML 바인딩에 대한 정보를 제공해 주셔서 감사합니다. – Scott