【发布时间】:2016-11-19 19:13:03
【问题描述】:
我想访问我创建的浮出控件的所有者。
我有代码:
public void dosomething(Grid lessonGrid)
{
var invisibleButton = new Button();
lessonGrid.Children.Add(invisibleButton);
var contentGrid = new Grid()
var buttonInFlyOut = new Button { Content="Click" };
buttonInFlyOut.Click += buttonClicked;
contentGrid.Children.Add(buttonInFlyOut);
var flyout = new FlyoutForLessons {
Content = contentGrid
};
flyout.Closed += (f, h) =>
{
lessonGrid.Children.Remove(invisibleButton);
};
flyout.Owner = lessonGrid;
flyout.ShowAt(invisibleButton); // i want to acces a owner from parent of invisible Button -> lessonGrid
}
private class FlyoutForLessons : Flyout
{
private static readonly DependencyProperty OwnerOfThisFlyOutProperty = DependencyProperty.Register(
"owner", typeof(UIElement), typeof(FlyoutForLessons),
null);
public UIElement Owner
{
get { return (UIElement) GetValue(OwnerOfThisFlyOutProperty); }
set { SetValue(OwnerOfThisFlyOutProperty, value); }
}
}
此代码向我展示了一个弹出窗口。因此,当我单击“buttonInFlyOut”按钮时,我想通过此方法从发件人那里获取“lessonGrid”的 ID:
private void buttonClicked_Click(object sender, RoutedEventArgs e)
{
}
如您所见,我尝试使用自定义属性创建一个新的 Flyout,但我无法通过上述方法从发件人那里获取此 Flyout。我不知道该怎么做,并且我不想创建一个私有静态变量来保留一个出现浮出控件的网格实例。
如果活树有帮助:
【问题讨论】: