WPFQ&A 200702
2007-02-05 09:14 爱车龟速兔 阅读(647) 评论(0) 编辑 收藏 举报Q:
Canves是否支持拖放?
A:
Canves 控件是支持拖放功能的,但是除了要设置canves空间的AllowDrop属性为true外,还要设置一下canves控件的background属性,如果不设置background属性, 这个Canves控件的拖放时没有效果的。
Q:
如何对ListView控件的数据进行排序?
A:
Demo代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<Grid.Resources>
<DataTemplate x:Key="HeaderTemplateArrowUp">
<DockPanel>
<TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
<Path x:Name="arrow"
StrokeThickness = "1"
Fill = "gray"
Data = "M 5,10 L 15,10 L 10,5 L 5,10"/>
</DockPanel>
</DataTemplate>
<DataTemplate x:Key="HeaderTemplateArrowDown">
<DockPanel>
<TextBlock HorizontalAlignment="Center" Text="{Binding }"/>
<Path x:Name="arrow"
StrokeThickness = "1"
Fill = "gray"
Data = "M 5,5 L 10,10 L 15,5 L 5,5"/>
</DockPanel>
</DataTemplate>
</Grid.Resources>
<ListView BorderBrush="Gray" x:Name="prtyList"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Name ="ctmAddPro" Header ="添加属性" Click ="ctmAddPro_Click" />
<MenuItem Name ="ctmModifyPro" Header ="修改属性" Click="ctmModifyPro_Click"/>
<MenuItem Name ="ctmDeletePro" Header ="删除属性" Click="ctmDeletePro_Click"/>
</ContextMenu>
</ListView.ContextMenu>
<ListView.View>
<GridView>
<GridViewColumn Header="属性中文名" Width="150" x:Name="prtyName"/>
<GridViewColumn Header="属性英文名" Width="150" x:Name="prtyAliasName"/>
<GridViewColumn Header="属性组" Width="150" x:Name="prtyGroup"/>
<GridViewColumn Header="属性类型" Width="120" x:Name="prtyType"/>
<GridViewColumn Header="属性值类型" Width="90" x:Name="prtyVType"/>
<GridViewColumn Header="非空" Width="90" x:Name="prtyNotNull"/>
<GridViewColumn Header="主键属性" Width="90" x:Name="prtyKey"/>
<GridViewColumn Header="继承自超类" Width="90" x:Name="prtyInherit"/>
<GridViewColumn Header="默认值" Width="90" x:Name="prtyDefault"/>
<GridViewColumn Header="长度" Width="90" x:Name="prtyLength"/>
<GridViewColumn Header="备注" Width="150" x:Name="prtyRemark"/>
</GridView>
</ListView.View>
</ListView>
private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
{
GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;
ListSortDirection direction;
if (headerClicked != null)
{
if (headerClicked.Role != GridViewColumnHeaderRole.Padding)
{
if (headerClicked != _lastHeaderClicked)
{
direction = ListSortDirection.Ascending;
}
else
{
if (_lastDirection == ListSortDirection.Ascending)
{
direction = ListSortDirection.Descending;
}
else
{
direction = ListSortDirection.Ascending;
}
}
string header = headerClicked.Column.Header as string;
Sort(header, direction);
if (direction == ListSortDirection.Ascending)
{
headerClicked.Column.HeaderTemplate =
Resources["HeaderTemplateArrowUp"] as DataTemplate;
}
else
{
headerClicked.Column.HeaderTemplate =
Resources["HeaderTemplateArrowDown"] as DataTemplate;
}
_lastHeaderClicked = headerClicked;
_lastDirection = direction;
}
}
}
private void Sort(string sortBy, ListSortDirection direction)
{
ICollectionView dataView =
CollectionViewSource.GetDefaultView(prtyList.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}
Q:
如何在xaml里使用资源?
A:
xmlns:resource="clr-namespace:OssWise.ConceptModel.Editor.Properties"
Icon="{x:Static resource:Resources.logolittle}"