2015-05-11 57 views
0

我一直在尝试根据不同的大小调整屏幕,以查看是否有任何组件对此作出反应。不幸的是,他们不 我不知道我错过了什么。如果任何人都可以给我的示例实现提供一个直接的建议和提示,那将会很棒。WPF应用程序的响应UI

下面是代码:

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="1000" Width="800"> 
    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="*"/> 
     </Grid.ColumnDefinitions> 

     <Grid.RowDefinitions> 
      <RowDefinition /> 
      <RowDefinition /> 
      <RowDefinition /> 
      <RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 
     <ListView Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
      <ListViewItem Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
       <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="*"/> 
        </Grid.ColumnDefinitions> 

        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition /> 
         <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
        <Expander HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="1" VerticalAlignment="Stretch"> 
         <Grid Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="20" /> 
           <ColumnDefinition Width="2*"/> 
           <ColumnDefinition Width="100" /> 
           <ColumnDefinition Width="20*"/> 
           <ColumnDefinition Width="Auto" /> 
          </Grid.ColumnDefinitions> 

          <Grid.RowDefinitions> 
           <RowDefinition /> 
           <RowDefinition /> 
           <RowDefinition /> 
           <RowDefinition Height="Auto" /> 
          </Grid.RowDefinitions> 
          <Label Grid.Column="1" Grid.Row="0" Content="HJello World meeee"/> 
          <ListView Grid.Column="3" Grid.Row="0" Grid.RowSpan="4"> 
           <ListView.ItemsPanel> 
            <ItemsPanelTemplate> 
             <StackPanel Orientation="Horizontal"></StackPanel> 
            </ItemsPanelTemplate> 
           </ListView.ItemsPanel> 
           <Button Content="Hello Tourist fu"/> 
           <Button Content="Hello Tourist fu"/> 
           <Button Content="Hello Tourist fu"/> 
           <Button Content="Hello Tourist fu"/> 
           <Button Content="Hello Tourist fu"/> 
           <ListViewItem Content="Test"/> 
          </ListView> 
          <Button Grid.Column="4" Grid.Row="0" Content="Test"/> 
         </Grid> 
        </Expander> 
       </Grid> 
      </ListViewItem> 
      <ListViewItem Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4"> 

       <Expander > 
        <Grid Width="Auto"> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="20" /> 
          <ColumnDefinition Width="2*"/> 
          <ColumnDefinition Width="100" /> 
          <ColumnDefinition Width="20*"/> 
          <ColumnDefinition Width="Auto" /> 
         </Grid.ColumnDefinitions> 

         <Grid.RowDefinitions> 
          <RowDefinition /> 
          <RowDefinition /> 
          <RowDefinition /> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <Label Grid.Column="1" Grid.Row="0" Content="HJello World meeee"/> 
         <ListView Grid.Column="3" Grid.Row="0" Grid.RowSpan="4"> 
          <ListView.ItemsPanel> 
           <ItemsPanelTemplate> 
            <StackPanel Orientation="Horizontal"></StackPanel> 
           </ItemsPanelTemplate> 
          </ListView.ItemsPanel> 
          <Button Content="Hello Tourist fu"/> 
          <Button Content="Hello Tourist fu"/> 
          <Button Content="Hello Tourist fu"/> 
          <Button Content="Hello Tourist fu"/> 
          <Button Content="Hello Tourist fu"/> 
          <ListViewItem Content="Test"/> 
         </ListView> 
         <Button Grid.Column="4" Grid.Row="0" Content="Test"/> 
        </Grid> 
       </Expander> 
      </ListViewItem> 
     </ListView> 

    </Grid> 
</Window> 
+0

你什么意思通过做“反应“? –

+0

我的意思是什么时候扩展器会确保适合屏幕(对应用程序的窗口变化做出反应) –

回答

1
  1. 设置x:Name你的主电网x:Name="Root"

  2. 设置为Expander属性Width="{Binding ActualWidth, ElementName=Root}"