如何使ContentControl水平拉伸

时间:2012-04-17 09:43:49

标签: silverlight layout

我已将Horizo​​ntalAlignment属性设置为拉伸,但它没有帮助。

我需要内容控件,因为在我的实际代码中,DataGrid会将prism注入内容控件。

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; }
}

1 个答案:

答案 0 :(得分:8)

您是否尝试将HorizontalContentAlignment属性设置为Stretch