일부 FrameworkElements를 동적으로 생성해야합니다. 나는 StackPanel에 있고, 나는 1 PivotItem으로, 그것은 피벗의 내부에 생성하고있는 ScrollViewer 안에 StackPanel에와 버튼이 같은 :ScrollView가 동적으로 생성 된 요소 내에서 작동하지 않습니다.
Pivot pivot = new Pivot();
PivotItem pivotItem = new PivotItem();
pivot.Items.Add(pivotItem);
ScrollViewer scrollViewer = new ScrollViewer();
StackPanel stackContent = new StackPanel();
scrollViewer.Content = stackContent;
pivotItem.Content = scrollViewer;
stackContent.Children.Add(new Button() { Content = "button 1" });
stackContent.Children.Add(new Button() { Content = "button 2" });
stackContent.Children.Add(new Button() { Content = "button 3" });
stackContent.Children.Add(new Button() { Content = "button 4" });
stackContent.Children.Add(new Button() { Content = "button 5" });
stackContent.Children.Add(new Button() { Content = "button 6" });
stackContent.Children.Add(new Button() { Content = "button 7" });
stackContent.Children.Add(new Button() { Content = "button 8" });
stackContent.Children.Add(new Button() { Content = "button 9" });
stackContent.Children.Add(new Button() { Content = "button 10" });
stackContent.Children.Add(new Button() { Content = "button 11" });
stkPanel.Children.Add(pivot);
을하고이 C#의 XAML 코드 :
<StackPanel x:Name="stkPanel">
</StackPanel>
XAML에서 모든 요소를 만들려고하면 ScrollViewer가 예상대로 작동하지만 페이지에서 일부 이벤트가 발생할 때 동적으로 만들어야합니다.
디버그에서 페이지를 검사하면 PivotItem의 "ActualHeight == 0"이므로 ScrollViewer가 그 이유 때문에 작동하지 않는다고 생각합니다. 그러나 ScrollViewer에 대한 수정 방법을 모르겠습니다. 스크롤을 작동 시키려면 "스스로 충전"하십시오.
XAML에서 모든 것을 만들 때 작업 코드를 추가 할 수 있습니까? 하지만 기본적으로 StackPanel은 필요한만큼 많은 공간을 사용하므로 StackPanel의 ScrollViewer는 내가 틀리지 않으면 작동하지 않아야합니다 ... – schumi1331
이것은 문제입니다, StackPanel ... 내가 Grid로 변경하면 모든 것이 작동합니다. 벌금! – CarlosTI