2011-03-08 85 views
0

我正在SurfaceListbox上工作,但我認爲該邏​​輯也適用於普通的WPF列表框。縮放Listbox/SurfaceListbox中的項目WPF

我有啓用水平滾動的surfacelistbox。它包含近20項。 surfacelistbox將被放置在屏幕的中心。現在,當用戶滾動列表框時,項目會水平移動,並根據列表框中每個項目的大小,我在屏幕上的任何給定時間通常會看到3個項目。

現在我想要做的是,當用戶停止滾動並且3個項目可見時,我想放大中心項目,即基本上放大它以突出顯示它。

有關如何在WPF中實現此類功能的任何指示將非常棒。由於用戶在滾動時沒有做出選擇,我無法使用selectionchanged事件來知道哪一個是中心項目。

回答

0

將SurfaceListBox放置在網格中,並使用RenderTransformOrigin =「0.5,0.5」將ScaleTransform綁定到網格中心範圍爲1到5的滑塊。

ItemsSource設置爲ObservableCollection;爲了幫助其他人遵循完整性,我在下面列出了一些定義。如果需要,我可以提供更多的代碼。

這裏查看:

<Window x:Class="SurfaceControls.MainWindow" 
    Icon="/Images/logo.gif" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Surface Toolkit Controls" Height="500" Width="600" 
    xmlns:my="http://schemas.microsoft.com/surface/2008" > 
    <Window.Resources> 
    <DataTemplate x:Key="EquipmentItemStyle"> 
     <StackPanel Orientation="Vertical"> 
      <TextBlock Text="{Binding Path=Id}"/> 
      <TextBlock Text="{Binding Path=EquipmentName}"/> 
      <TextBlock Text="{Binding Path=EquipmentType}"/> 
     </StackPanel> 
    </DataTemplate> 
    </Window.Resources> 
    <Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition/> 
     <RowDefinition Height="Auto"/> 
    </Grid.RowDefinitions> 
    <Grid RenderTransformOrigin="0.5,0.5" Grid.Row="0"> 
     <Grid.RenderTransform> 
      <TransformGroup> 
       <ScaleTransform 
        ScaleY="{Binding Path=Value, ElementName=slider}" 
        ScaleX="{Binding Path=Value, ElementName=slider}"/> 
      </TransformGroup> 
     </Grid.RenderTransform> 
     <my:SurfaceListBox 
       ItemsSource="{Binding Path=Equipment, Mode=TwoWay}" 
       SelectedItem="{Binding Path=SelectedEquipment, Mode=TwoWay}" 
       ItemTemplate="{StaticResource ResourceKey=EquipmentItemStyle}" > 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" 
           VerticalAlignment="Stretch" 
           HorizontalAlignment="Center"/> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
     </my:SurfaceListBox> 
    </Grid> 
    <StackPanel Grid.Row="1" Orientation="Horizontal"> 
     <my:SurfaceSlider Ticks="5" 
           Width="100" 
           Minimum="1" 
           Interval="1" 
           Maximum="5" 
           x:Name="slider" 
           VerticalAlignment="Center" 
           Margin="4,4,4,4"/> 
    </StackPanel> 
    </Grid> 
</Window> 

下面這個集合的列表框的約束:

private ObservableCollection<Equipment> _equipment = new ObservableCollection<Equipment>(); 
public ObservableCollection<Equipment> Equipment 
{ 
    get 
    { 
    return _equipment; 
    } 
    set 
    { 
    _equipment = value; 
    } 
} 

和模型的確定指標:

public class Equipment 
{ 
    public int Id { get; set; } 
    public string EquipmentName { get; set; } 
    public string EquipmentType { get; set; } 
}