问题
I have this binding in xaml:
<Popup IsOpen="{Binding Path=(local:ListViewBehavior.IsColumnHeaderClicked),
RelativeSource={RelativeSource FindAncestor, AncestorType=GridViewColumnHeader}}" ...
Popup
is located inside GridViewColumn.Header
.
ListViewBehavior.IsColumnHeaderClicked
is a simple bool
attached property:
public static bool GetIsColumnHeaderClicked(DependencyObject obj) => (bool)obj.GetValue(IsColumnHeaderClickedProperty);
public static void SetIsColumnHeaderClicked(DependencyObject obj, bool value) => obj.SetValue(IsColumnHeaderClickedProperty, value);
public static readonly DependencyProperty IsColumnHeaderClickedProperty =
DependencyProperty.RegisterAttached("IsColumnHeaderClicked", typeof(bool), typeof(ListViewBehavior), new PropertyMetadata(false));
Its value is set by some code behind:
void listView_ColumnClicked(object sender, RoutedEventArgs e)
{
var column = (DependencyObject)e.OriginalSource;
SetIsColumnHeaderClicked(column, !GetIsColumnHeaderClicked(column)); // toggle
}
Idea is to show popup when GridViewColumnHeader
is clicked. Everything so far is working.
Question: how bind this attached property to IsPopupOpen
property in my ViewModel?
I was thinking about some kind of proxy which is used to bind to attached property and to ViewModel property at same time. Or perhaps I should bind to IsOpen
again? Bind twice? Is this even possible?
来源:https://stackoverflow.com/questions/36041383/attached-property-binding-proxy