2
我已經將HorizontalAlignment屬性設置爲伸展,但沒有幫助。如何使ContentControl水平拉伸
我需要該內容控件,因爲在我的真實代碼中,DataGrid是用棱鏡注入到內容控件中的。
XAML:
<ContentControl HorizontalAlignment="Stretch">
<Grid>
<Controls:DataGrid ItemsSource="{Binding Persons}"></Controls:DataGrid>
</Grid>
</ContentControl>
後面的代碼:
public partial class MainPage : UserControl
{
public List<Person> Persons { get; set; }
public MainPage()
{
Persons = new List<Person>();
Persons.Add(new Person { Name = "A",Age = 5});
Persons.Add(new Person { Name = "A", Age = 5 });
Persons.Add(new Person { Name = "A", Age = 5 });
InitializeComponent();
DataContext = this;
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}