2016-09-25 5 views
-1

Scrollviewerが下にスクロールされていることを確認できますか? 私のXMLコード:ScrollBarの位置を確認

<ScrollViewer x:Name="scroll" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> 
    <ListBox x:Name="chat" Height="290" VerticalAlignment="Top" Width="440" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True" > 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid Width="410"> 
        <TextBlock TextWrapping="WrapWithOverflow" Margin="0,1"> 
         <Run Text="{Binding Name}" Foreground="{Binding Color}" FontWeight="Bold"/> 
         <Run Text=": "/> 
         <Run Text="{Binding Message}"/> 
        </TextBlock> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</ScrollViewer> 

答えて

0

は、そのVerticalOffsetScrollViewerScrollableHeightの比較します。それは二重で、私を心配しましたが、実際に比較のデモがあります。

public class HeightConverter : IMultiValueConverter 
{ 
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) 
    { 
     double d1 = (double)values[0], d2 = (double)values[1]; 
     return (d1 == d2 ? "equal" : "not equal"); 
    } 

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

    <Window x:Class="WpfApplication4.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:WpfApplication4" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     Width="300" Height="200"> 

    <Window.Resources> 
     <local:HeightConverter x:Key="HeightConverter" /> 
    </Window.Resources> 

    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="auto" /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <TextBlock> 
      <TextBlock.Text> 
       <MultiBinding Converter="{StaticResource HeightConverter}"> 
        <Binding ElementName="Scroll" Path="VerticalOffset" /> 
        <Binding ElementName="Scroll" Path="ScrollableHeight" /> 
       </MultiBinding> 
      </TextBlock.Text> 
     </TextBlock> 

     <ScrollViewer x:Name="Scroll" Height="200" VerticalScrollBarVisibility="Auto" CanContentScroll="True" Grid.Row="1"> 
      <ListBox> 
       <!-- long list of items --> 
      </ListBox> 
     </ScrollViewer> 
    </Grid> 

</Window> 
+0

私はスクロールバーを動かしていますが、ScrollableHeightとVerticalOffsetは常に返す:0 :( – Nostradamus

+0

@Nostradamusあなたはコードビハインドから何かをやっている私は新しいスレッドでのListBoxに項目を追加しているコードビハインドで –

+0

を? 。 – Nostradamus

関連する問題