2011-02-13 50 views
2

我有一些用户控件,我把它放在一个窗口控件中,我不想在用户控件中有一个固定的大小,我希望它抓住所有的空间,我把它。我应该添加到我的代码?使用户控件伸展到所有给定的空间

<UserControl x:Class="DBTool.View.SelectDataBase" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      > 


    <UserControl.Background > 
     <ImageBrush ImageSource="..\Resources\DBSelection.jpg" ></ImageBrush > 
    </UserControl.Background > 

    <Grid> 
    <ItemsControl FontWeight="Normal" ItemsSource="{Binding Path=AvailableBeanTypes}" > 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <RadioButton 
       Content="{Binding Path=DisplayName}" 
       IsChecked="{Binding Path=IsSelected}" 
       GroupName="BeanType" 
       Margin="2,3.5" 
       /> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 
    </Grid> 
</UserControl> 

我的窗口代码

<Window x:Class="DBTool.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:View="clr-namespace:DBTool.View" 
     xmlns:ViewModel="clr-namespace:DBTool.ViewModel" 
     Title="MainWindow" Height="332" Width="528" > 

    <Window.Resources> 

     <!-- These four templates map a ViewModel to a View. --> 
     <DataTemplate DataType="{x:Type ViewModel:SelectDataBaseViewModel}"> 
      <View:SelectDataBase /> 
     </DataTemplate> 

     <DataTemplate DataType="{x:Type ViewModel:MySqlPageViewModel}"> 
      <View:MySqlPageView /> 
     </DataTemplate> 



    </Window.Resources> 

      <DockPanel LastChildFill="True" > 


     <ToolBar Height="26" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="toolBar1" Width="Auto" DockPanel.Dock="Top" /> 

     <Grid VerticalAlignment="Bottom" DockPanel.Dock="Bottom" > 
      <Grid.RowDefinitions> 
       <RowDefinition/> 
      </Grid.RowDefinitions> 

      <Grid.ColumnDefinitions> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
       <ColumnDefinition/> 
      </Grid.ColumnDefinitions> 

      <Button Grid.Row="0" Grid.Column="4" Background="Azure" Margin="10" Command="{Binding Path=MoveNextCommand}" > Next </Button> 

      <Button Grid.Row="0" Grid.Column="3" Background="Azure" Margin="10" Command="{Binding Path=MovePreviousCommand}"> Previous </Button> 

      <TextBox Name="txtInput" Grid.Column="1"/> 
      <Label Content="{Binding Text, ElementName=txtInput, 
        UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" /> 


     </Grid> 
     <!-- <View:SelectDataBase x:Name="DetailView"/>--> 
     <Border Background="White" Grid.Column="1" Grid.Row="0"> 
      <HeaderedContentControl 
     Content="{Binding Path=CurrentPage}" 
     Header="{Binding Path=CurrentPage.DisplayName}" 
     /> 
     </Border> 
    </DockPanel> 


</Window> 

enter image description here

但我想看到的图像把整个空白那里。

+0

重复:http://stackoverflow.com/questions/36108/how-to-get-controls-in-wpf-to-fill-available-空间 – 2011-02-13 09:34:26

回答

2

您需要了解panels(网格,堆栈等)及其属性。高度和宽度属性,如果我记得在wpf中有一个“*”值,它通过百分比。

这是一个agreat WPF教程

http://www.wpftutorial.net/

相关问题