사실 LastChildFill와 WPF DockPanel에서 마지막 자식을 교체, 마지막 자식은 전체 사용되지 않는 공간을 차지했다. 이제는 프로그래밍
UIElementCollection children = myDockPanel.Children;
UIElement uie = new myBestControl();
children.RemoveAt(children.Count - 1);
children.Add(uie);
, 새로 추가 된 컨트롤이 더 이상 공간을 채우기 : 나는 프로그래밍 마지막 자식을 교체 할 때까지, 잘 작동하지
.
문제를 어떻게 해결해야합니까? 당신이 그것을 가지고 버튼, 텍스트 하나, 텍스트 블록을 교체 클릭 할 때이 XAML
<DockPanel x:Name="MyDock" LastChildFill="True">
<TextBlock DockPanel.Dock="Left"
MouseDown="TextBlock_MouseDown">Child 1</TextBlock>
<TextBlock DockPanel.Dock="Left">Child 2</TextBlock>
<TextBlock>Child 3</TextBlock>
</DockPanel>
및
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
UIElementCollection children = MyDock.Children;
Button btn = new Button();
btn.Background = Brushes.LightBlue;
children.RemoveAt(children.Count - 1);
children.Add(btn);
}
뒤에이 코드와 함께 나를 위해 작동