2012-04-17 77 views
2

我已经将Horizo​​ntalAlignment属性设置为伸展,但没有帮助。如何使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; } 
} 

回答

8

你有没有尝试设置HorizontalContentAlignment属性为Stretch