我想访问我创建的flyout的所有者。
我有代码:
LightIntegration.Browser.QUnit.Firefox:
OpenQA.Selenium.WebDriverException : Cannot find a file named '...\bin\Debug\getAttribute.js' or an embedded resource with the id 'getAttribute.js'.
此代码显示了弹出窗口。因此,当我点击“buttonInFlyOut”按钮时,我希望在此方法中从发件人获取“lessonGrid”的ID:
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); }
}
}
如您所见,我尝试使用自定义属性创建一个新的Flyout,但我无法通过上述方法从发件人处获取此弹出窗口。我不知道该怎么做,而且我不想创建一个私有静态变量,它保持一个网格实例出现弹出窗口。
如果活树有帮助:
答案 0 :(得分:3)
没有理由不能像这样处理你的点击事件:
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 += (o, args) =>
{
this.OnButtonClicked(lessonGrid);
};
contentGrid.Children.Add(buttonInFlyOut);
var flyout = new Flyout { Content = contentGrid };
flyout.Closed += (f, h) => { lessonGrid.Children.Remove(invisibleButton); };
flyout.ShowAt(invisibleButton); // i want to acces a owner from parent of invisible Button -> lessonGrid
}
private void OnButtonClicked(Grid lessonGrid)
{
// Do something here
}
这允许您访问传入方法的网格。
由于Flyout不是FrameworkElement的方式,你永远不会在可视化树中找到它,这就是为什么你看到截图中的弹出窗口在框架之外。如果没有设置您在方法中访问的属性或者按照我上面描述的方式尝试它,我认为不可能这样做。