<Popup x:Name="dispatchPop"
PlacementTarget="{Binding ElementName=griddatalist}"
StaysOpen="True"
IsOpen="False"
Width="{Binding ElementName=griddatalist, Path=ActualWidth, Converter={StaticResource actualWidth}}" Height="20"
Placement="Left"
Placement="Bottom"
PopupAnimation="Fade"
AllowsTransparency = "True"
x:Name="dispatchPop"
HorizontalOffset="{Binding ElementName=griddatalist, Path=ActualWidth,UpdateSourceTrigger=PropertyChanged}"
>
<Popup.VerticalOffset>
<MultiBinding Converter="{StaticResource ver}">
<Binding ElementName="griddatalist,Path=DataContext,UpdateSourceTrigger=PropertyChanged"/>
<Binding ElementName="griddatalist" Path="ActualHeight" UpdateSourceTrigger="PropertyChanged"/>
<Binding ElementName="griddatalist" Path="ActualWidth" UpdateSourceTrigger="PropertyChanged"/>
</MultiBinding>
</Popup.VerticalOffset>
VerticalOffset="-15" >
<Border Width="{Binding ElementName=griddatalist, Path=ActualWidth}" Height="20" Background="{StaticResource SelectedLine}">
<TextBlock x:Name="selectedCount" Height="20" Width="55" Margin="8,2,8,2" FontSize="12" Foreground="#FFFFFF"/>
<TextBlock x:Name="selectedCount" Height="20" Width="55" Margin="8,2,8,2" FontWeight="Bold" FontSize="12" Foreground="#FFFFFF"/>
</Border>
</Popup>
主要是这句话
<MultiBinding Converter="{StaticResource ver}">
<Binding ElementName="griddatalist"/>#这里绑定了控件
<Binding ElementName="griddatalist" Path="ActualHeight" UpdateSourceTrigger="PropertyChanged"/>
<Binding ElementName="griddatalist" Path="ActualWidth" UpdateSourceTrigger="PropertyChanged"/>
</MultiBinding>
下面是converter
public class DispatchListPopupVer : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
DataGrid grid = values[0] as DataGrid;
double horizon = 0;
double.TryParse(values[1].ToString(), out horizon);
ScrollViewer scrollview = FindVisualChild<ScrollViewer>(grid);
if (scrollview != null)
{
if (scrollview.ComputedHorizontalScrollBarVisibility== Visibility.Visible)
{
return horizon - 34;
}
else
{
return horizon - 20;
}
}
else
{
return horizon - 34;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
private childItem FindVisualChild<childItem>(DependencyObject obj)
where childItem : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else
{
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
}