나는 Pivot.HeaderTemplate
에 헤더를 설정 한 Pivot
을 가지고 있습니다. 기본적으로 Books의 Names
을 보여주는 것입니다. 내 Pivot.ItemTemplate
에서 Grid
은 내 .xaml.cs에 빌드를 표시하려고하지만 Grid
은 내 DataTemplate
에 있기 때문에 .xaml.cs의 코드 뒤에 더 이상 Grid x:Name
에 액세스 할 수 없습니다. books
내가 뒤에 BooksGrid
INY 코드를 액세서 실제로 Grid
Datatemplate 내의 UWP Grid
를 만들
<Pivot ItemsSource="{x:Bind books}">
<Pivot.HeaderTemplate>
<DataTemplate x:DataType="local:Book">
<TextBlock Text="{x:Bind Name}"/>
</DataTemplate>
</Pivot.HeaderTemplate>
<Pivot.ItemTemplate>
<DataTemplate>
<Grid
x:Name="BooksGrid"
BorderBrush="Black" BorderThickness="1 1 0 0"
Margin="0 10 0 0>
</Grid>
</DataTemplate>
</Pivot.ItemTemplate>
이제 Name
과 Title
에서 MainPage.xaml이 들어 책의 모음입니다 MainPage.xaml.cs
public MainPage()
{
this.InitializeComponent();
}
private void DrawGrid()
{
//create columns of Grid
for (int i = 0; i < booksize.XProperties.Count + 1; i++)
{
BooksGrid.ColumnDefinitions.Add(new ColumnDefinition
{
});
}
BooksGrid.ColumnDefinitions[0].Width = GridLength.Auto;
}
....
이미 여기 BooksGrid.ColumnDefinitions.Add(...)
에 BooksGrid
을 찾을 수 없습니다. 내 정의를 내 DataTemplate
에 넣지 않고 내 Pivot
외부에 배치하면 내 DrawGrid
이 작동합니다. Grid
내가 솔루션은 즉시 DataTemplate
가로드되는대로, 내가 작업 할 Grid instance
을 액세서해야한다는 수 있습니다 읽었습니다 내 DataTemplate
내부에있을 때 그래서 MainPage.xaml.cs
그것을 발견하지 않습니다. 그러나 나는 그것을 어떻게 할 지 모른다. 최초의 솔루션에
편집 PART : 그것은 동적으로 생성되기 때문에
나는 또한 당신이 액세스 할 수 없습니다 MainPage.xaml.cs를
private void DrawBooksFront(Front front)
{
int row;
int column;
column = booksize.XProperties.IndexOf(front.CustomProps[booksize.XLabel])+1;
row = booksize.YProperties.IndexOf(front.CustomProps[booksize.YLabel])+1;
Frame newFrame = new Frame();
TaskBoardGrid.Children.Add(newFrame);
Grid.SetColumn(newFrame, column);
Grid.SetRow(newFrame, row);
}
당신은 DateTemplate을 찾을 수 없습니다해야하며 그것은 나에게 의미가 있지만 나는 또한'공공 무효 DrawBooksFront (전면 앞)'라고 다른 방법으로'BooksGrid'을 사용하고있는 UserControl – lindexi