2016-03-31 27 views
0

で親幅を超えるのは、私は次のXAMLを持っているとしましょう:レイアウトのリストボックスは、WPF

<Grid MaxHeight="200" d:LayoutOverrides="Width"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition Width="Auto"/> 
    </Grid.ColumnDefinitions> 
    <ListBox Height="170" ScrollViewer.HorizontalScrollBarVisibility="Visible" ItemsSource="{Binding DataModel.LocalData.ListFabricRules}" IsEnabled="{Binding DataModel.LocalData.Enabled}" SelectedItem="{Binding DataModel.LocalData.ListFabricRulesSelected}" > 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <TextBlock Text="{Binding Descript}" /> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
    <StackPanel Grid.Column="1" Orientation="Vertical" d:LayoutOverrides="Height" Margin="10,0" IsEnabled="{Binding DataModel.LocalData.EnabledRules}"> 
     <Button Content="Test" /> 
    </StackPanel> 
</Grid> 

目標は、リストボックスが(列)、および右側にある空きスペースを埋めることですリストボックスにはボタンがあります。 問題は次のとおりです。リストボックスに(スクロールしたテキストが大きいために)横スクロールが表示されると、幅の増分がグリッドの比率を変更するため、ボタンが余白を尊重せずにメイングリッドを超えて右に移動します。 Scrollviewerの内部にメイングリッドを配置すると、スクロールが部分的に非表示になります。メイングリッドのホストはusercontrolです。ここで

Click here you can see the image where is the listbox without horizontal scroll. You can the scroll of scrollviewer.In this capture no problem

In this image there are large items (horizontally), so the horizontal scroll in listbox is visible. In this case, the scroll of scrollviewer is partially hide. It's because the listbox has more width. I don't know why

答えて

1

問題は、それが両方の列の自動車」として取っているリストボックスの幅を定義していない、です。 これを解決するには、*を使用して幅のパーセンテージを設定するか、 MaxまたはMinWidthを使用する必要があります。

<Grid MaxHeight="200" d:LayoutOverrides="Width"> 
<Grid.ColumnDefinitions> 
    <ColumnDefinition Width="80*"/> 
    <ColumnDefinition Width="20*"/> 
</Grid.ColumnDefinitions> 
<ListBox Height="170" ScrollViewer.HorizontalScrollBarVisibility="Visible" ItemsSource="{Binding DataModel.LocalData.ListFabricRules}" IsEnabled="{Binding DataModel.LocalData.Enabled}" SelectedItem="{Binding DataModel.LocalData.ListFabricRulesSelected}" > 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Grid> 
       <TextBlock Text="{Binding Descript}" /> 
      </Grid> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
<StackPanel Grid.Column="1" Orientation="Vertical" d:LayoutOverrides="Height" Margin="10,0" IsEnabled="{Binding DataModel.LocalData.EnabledRules}"> 
    <Button Content="Test" /> 
</StackPanel> 

+0

親愛なるロビン、私は解決策を証明しますが、動作しません。水平スクロールが表示されているときにリストボックスの幅が増えます。リストボックスには、ボタンが残る幅の余りがあることが必要です。添付画像では、スクロールビューアを使うことができますが、スクロールビューアを使用せずに解決策を試しましたが、動作は同じです。 – Aitor

関連する問題