单击时C#XAML列表框将崩溃
我是WindowsPhone8.1的XAML新手,在这方面遇到了一些问题单击时C#XAML列表框将崩溃,c#,xaml,user-interface,windows-phone-8.1,listboxitem,C#,Xaml,User Interface,Windows Phone 8.1,Listboxitem,我是WindowsPhone8.1的XAML新手,在这方面遇到了一些问题 使堆叠面板可单击 单击时折叠项目 到目前为止,我的工作如下: 代码(如果有重大缺陷,请纠正我): 所以我的问题是: 每当我点击列表框中的每个项目时,如何对其进行美观的展开/折叠 非常感谢您。真正的问题是,您希望它崩溃成什么样子?有太多可能的方法来折叠某些可视数据项。您只是想更改项目的高度,还是想要一些折叠某些属性的奇特动画 如果高度是你想要的,那就很容易了。只需在您的边框上附加一个点击事件。另一方面,您可能希望编辑Ite
列表框
中的每个项目时,如何对其进行美观的展开/折叠
非常感谢您。真正的问题是,您希望它崩溃成什么样子?有太多可能的方法来折叠某些可视数据项。您只是想更改项目的高度,还是想要一些折叠某些属性的奇特动画
如果高度是你想要的,那就很容易了。只需在您的边框上附加一个点击事件
。另一方面,您可能希望编辑ItemContainerStyle
使其具有
,这样列表框将在屏幕上延伸,否则它将不可用
行动中的代码
这只是你问题的一个快速解决方案。这里的一些人希望您在VisualStateManager
中的Selected
状态的高度属性上创建StoryBoard
动画。如果您改写或创建了一个新问题,明确说明您需要VisualStateManager
解决方案,我也会为您提供一个。祝你好运。真正的问题是,你希望它崩溃成什么样子?有太多可能的方法来折叠某些可视数据项。您只是想更改项目的高度,还是想要一些折叠某些属性的奇特动画
如果高度是你想要的,那就很容易了。只需在您的边框上附加一个点击事件
。另一方面,您可能希望编辑ItemContainerStyle
使其具有
,这样列表框将在屏幕上延伸,否则它将不可用
行动中的代码
这只是你问题的一个快速解决方案。这里的一些人希望您在VisualStateManager
中的Selected
状态的高度属性上创建StoryBoard
动画。如果您改写或创建了一个新问题,明确说明您需要VisualStateManager
解决方案,我也会为您提供一个。祝您好运。的可能重复?不幸的是,这是针对WPF的,Windows Phone不接受StackPanel_MouseEnter和StackPanel_Mouseleve等事件。另外,解决方案不适用于winPhone。您是否尝试过点击事件处理程序?可能重复?不幸的是,这是针对WPF的,Windows Phone不接受StackPanel_MouseEnter和StackPanel_MouseLeave等事件。此外,解决方案不适用于winPhone。您是否尝试过Tap事件处理程序?
<Border CornerRadius="15" Background="#FF595656" Margin="0" Grid.ColumnSpan="2" Height="80">
<StackPanel Orientation="Horizontal">
<StackPanel Width="20" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel HorizontalAlignment="Left" Height="80" Margin="0,0,0,0" VerticalAlignment="Center" Width="51">
<Image HorizontalAlignment="Left" Height="51" Margin="0,15,0,0" Width="51" Source="Assets/fish.png" Stretch="Fill" RenderTransformOrigin="2.307,0.881" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Width="10" HorizontalAlignment="Left" VerticalAlignment="Top" />
<StackPanel HorizontalAlignment="Left" Height="80" Margin="0" VerticalAlignment="Top" Width="310">
<TextBlock HorizontalAlignment="Left" Height="25" Margin="0,20,0,0" TextWrapping="Wrap" Text="Entry 1" Width="310" VerticalAlignment="Top" FontSize="18" Foreground="Black" FontWeight="Bold"/>
<TextBlock HorizontalAlignment="Left" Height="17" Margin="0" TextWrapping="Wrap" Text="Short description Entry 1" Width="310" VerticalAlignment="Top" Foreground="#FF0097FF"/>
</StackPanel>
</StackPanel>
</Border>
<ListBox x:Name="ListBox1" Margin="0"
Width="400" Height="200" HorizontalAlignment="Left"
ItemsSource="{Binding}" Grid.Row="1" VerticalAlignment="Top" Grid.ColumnSpan="2" >
<ListBox.ItemTemplate>
<DataTemplate>
// the code above
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="0,1" Tap="Border_Tap">
<StackPanel>
<!--- rest of template --->
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
private void Border_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
int minHeight = 40; // change to whatever you want
Border b = sender as Border;
if (b.ActualHeight > minHeight)
{
b.Height = minHeight;
}
else
{
b.Height = double.NaN; // this will change the height back to Auto, showing everything
}
}