Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Listbox/SurfaceListbox WPF中缩放项目_Wpf_Listbox_Pixelsense - Fatal编程技术网

在Listbox/SurfaceListbox WPF中缩放项目

在Listbox/SurfaceListbox WPF中缩放项目,wpf,listbox,pixelsense,Wpf,Listbox,Pixelsense,我正在研究SurfaceListbox,但我认为逻辑也适用于普通WPF listbox 我已启用水平滚动的surfacelistbox。它包含近20个项目。surfacelistbox将被放置在屏幕的中心。现在,当用户滚动列表框时,项目水平移动,并且基于列表框中每个项目的大小,我已经看到在屏幕上的任何给定时间,通常有3个项目是可见的 现在我想做的是,当用户停止滚动并且3个项目可见时,我想放大中心项目,即基本上放大它以突出显示它 任何关于如何在WPF中实现此类功能的指针都将非常有用。由于用户在滚动

我正在研究SurfaceListbox,但我认为逻辑也适用于普通WPF listbox

我已启用水平滚动的surfacelistbox。它包含近20个项目。surfacelistbox将被放置在屏幕的中心。现在,当用户滚动列表框时,项目水平移动,并且基于列表框中每个项目的大小,我已经看到在屏幕上的任何给定时间,通常有3个项目是可见的

现在我想做的是,当用户停止滚动并且3个项目可见时,我想放大中心项目,即基本上放大它以突出显示它


任何关于如何在WPF中实现此类功能的指针都将非常有用。由于用户在滚动时没有进行选择,因此我无法使用selectionchanged事件来确定哪一个是中心项。

将SurfaceListBox放置在网格中,并使用RenderTransferMorigin=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; }
}