【发布时间】:2011-04-18 07:08:09
【问题描述】:
Photosuru 具有简洁的效果 - 当您将鼠标悬停在缩略图上时,会打开一个显示放大图像的弹出窗口。我试图让它在列表框上工作,类似于工具提示,我需要将鼠标悬停在一个项目上并打开弹出窗口。问题是,弹出窗口只显示在列表框中选择的项目。我尝试通过 Photosuru 代码寻找答案,但发现它对我来说太先进了。注意:我不能使用工具提示,因为它是其他东西所需要的。
这是 xaml:
<Window.Resources>
<XmlDataProvider x:Key="MyPartsXML"
Source="F:\ListBoxSync\MyParts.xml"
XPath="MyParts"/>
</Window.Resources>
<Grid x:Name="MainGrid"
DataContext="{Binding ElementName=PartsList, Path=SelectedItem}"
Width="Auto"
VerticalAlignment="Stretch">
<ListBox ItemsSource="{Binding Source={StaticResource MyPartsXML},
XPath=//MyParts//parts}"
IsSynchronizedWithCurrentItem="True"
Name="PartsList"
HorizontalAlignment="Left">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="2" BorderBrush="Black" Margin="10">
<TextBlock Name="lstbxBlock"
Text="{Binding XPath=item}"
MouseEnter="item_MouseEnter"
MouseLeave="item_MouseLeave"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Popup x:Name="Pops"
IsOpen="False"
Placement="Right"
StaysOpen="False"
PlacementTarget="{Binding ElementName=txtBxitem}"
HorizontalAlignment="Left">
<StackPanel>
<TextBox Text="{Binding XPath=color}"/>
<TextBox Text="{Binding XPath=size}"/>
</StackPanel>
</Popup>
<TextBox Text="{Binding XPath=color}"/>
<TextBox Text="{Binding XPath=size}"/>
</Grid>
背后的代码:
private void item_MouseEnter(object sender, MouseEventArgs e)
{
this.Pops.IsOpen = true;
}
private void item_MouseLeave(object sender, MouseEventArgs e)
{
this.Pops.IsOpen = false;
}
希望这不是矫枉过正,但这里是 xml:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<MyParts>
<parts>
<item>Part1</item>
<color>Red</color>
<size>SM</size>
</parts>
<parts>
<item>Part2</item>
<color>Green</color>
<size>LG</size>
</parts>
<parts>
<item>Part3</item>
<color>Blue</color>
<size>XXL</size>
</parts>
<parts>
<item>Part4</item>
<color>Yellow</color>
<size>LG</size>
</parts>
<parts>
<item>Part5</item>
<color>Green</color>
<size>XL</size>
</parts>
【问题讨论】:
标签: wpf xml listbox popup mouseover