[英]WPF DisplayMemberBinding on MultiBinding columns
I have a ListView
, and I want to be able to sort any column of it, using CollectionView
.我有一个
ListView
,我希望能够使用CollectionView
对它的任何列进行排序。
When I have a simple binding I meet no problem to set the PropertyName
of my SortDescription
:当我有一个简单的绑定时,设置我的
SortDescription
的PropertyName
没有问题:
header = ((System.Windows.Data.Binding)headerClicked.Column.DisplayMemberBinding).Path.Path;
But when I have a MultiBinding, is there a way to take the Path of the first or second binding path?但是当我有一个 MultiBinding 时,有没有办法取第一个或第二个绑定路径的路径?
My XAML is made so :我的 XAML 是这样制作的:
<GridViewColumn Header="{x:Static p:Resources.Quantite}" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource :displayQteSurQteTot}">
<Binding Path="Quantite" />
<Binding Path="TotalQuantity" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</WrapPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
But when I have a
MultiBinding
, is there a way to take thePath
of the first or second binding path?但是,当我有一个
MultiBinding
,有没有办法拿Path
的第一或第二结合路径?
Not from the GridViewColumnHeader
nor the GridViewColumn
since the MultiBinding
is only applied to the TextBlock
element in the CellTemplate
.不是来自
GridViewColumnHeader
也不是来自GridViewColumn
因为MultiBinding
仅应用于CellTemplate
的TextBlock
元素。
But you could create an attached property and set the path for each column explicitly:但是您可以创建一个附加属性并明确设置每列的路径:
public class GridViewColumnExtensions
{
public static readonly DependencyProperty PathProperty = DependencyProperty.RegisterAttached(
"Path",
typeof(string),
typeof(GridViewColumnExtensions),
new FrameworkPropertyMetadata(null)
);
public static void SetPath(GridViewColumn element, string value)
{
element.SetValue(PathProperty, value);
}
public static string GetPath(GridViewColumn element)
{
return (string)element.GetValue(PathProperty);
}
}
XAML: XAML:
<GridViewColumn Header="{x:Static p:Resources.Quantite}" Width="50" local:GridViewColumnExtensions.Path="test">
Usage:用法:
string header = GridViewColumnExtensions.GetPath(headerClicked.Column);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.