【发布时间】:2013-05-09 00:09:05
【问题描述】:
我在这里遇到了两个问题。我有一个填充了一些项目的 DataGrid。我想要发生的是在 DataGrid 选定行下显示一个 Popup 控件。这是我所拥有的:
<Grid>
<DataGrid CanUserReorderColumns="False"
CanUserSortColumns="False"
HeadersVisibility="None"
AutoGenerateColumns="False"
VerticalAlignment="Stretch"
ItemsSource="{Binding ItemCollection}"
SelectedItem="{Binding SelectedItem}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding Path=Key}" />
<DataGridTextColumn Width="*" Binding="{Binding Path=Value}" />
</DataGrid.Columns>
</DataGrid>
<Popup PopupAnimation="Scroll" Placement="Bottom" AllowsTransparency="True" IsOpen="{Binding PopupVisible}" Margin="0" StaysOpen="True" >
<local:PopupControl />
</Popup>
</Grid>
当 SelectedItem 像这样更改时,我在 ViewModel 中设置 IsOpen 属性:
PopupVisible = true;
使用此代码,我可以显示弹出框。
第一个问题:使用 StaysOpen = "True" 移动窗口时弹出窗口不会移动。我使用 Button 控件处理此问题的方法是将 StaysOpen 更改为“False”,以便在单击窗口中的其他位置时关闭弹出窗口。当我使用 DataGrid 控件执行此操作时,当 SelectedItem 更改时,弹出窗口根本不会显示。这是为什么呢?
第二个问题:如何让弹出窗口显示在所选行下方?
【问题讨论】:
-
在弹出的 xaml 块中,更改 Placement="MousePoint",然后在 datagrid 的单元格单击事件中更改 IsOpen="True"。
标签: c# wpf mvvm datagrid popup