微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从Flyout XAML中的button访问Flyout

我觉得这是一个菜鸟XAML的问题,但是这里呢。

我想要做的是:我正在开发一个Windows Phone 8.1应用程序,并且我想为自定义popup窗口添加function,以便在连续两次单击popup窗口中的相同菜单button时closurespopup窗口。 例如:用户单击popup窗口中的“转到设置”菜单项。 如果用户现在再次点击它,这意味着我们已经在设置菜单中,因此我只想closurespopup窗口。

问题:我的问题是,我需要一些方法可以在popup窗口中调用代码,当它里面的一个button被点击。 因为我正在和MVVMCross和Xamarin合作(我不想将windows-phone特定的逻辑转移到通用平台视图模型中),所以我没有办法在这里做任何代码

尝试到目前为止:我已经尝试通过使自定义button从buttoninheritance来解决此问题。 当button加载时,一个事件被订阅了它的轻敲事件。 当发生这种情况时,我尝试通过recursion地查看button的父级(然后是父级的父级),直到find它,尝试获取popup窗口的句柄。 …这是行不通的,因为我从来没有把Flyout作为父母,而是让我有一个Flyout-Presenter(不允许我访问我的自定义popup窗口),所以我不能调用我想要的function。

活动窗口上是否有Windows系统事件更改?

如何让多点触摸与JWinPointer在libGDX中正常工作?

使用Charset.forName为UTF-7获取不同的结果在Linux和Windows上

REGEX:DOS FindStr命令没有反类function?

PHPStorm无法parsingPHPUnit版本输出。 非常奇怪的错误

我曾尝试制作一个自定义的“FlyoutButton”,它inheritance自Button。 这个button有一个可以在XAML中设置的Flyout的DependencyProperty,所​​以我有一个button内部popup的句柄。 当我尝试这样做时,我只得到exception“System.Void不能从C#中使用”,我真的搞不明白,为什么我得到。 下面是我的代码看起来如何。

我的代码 XAML代码片段:

<Button.Flyout> <controls:MainMenuFlyout x:Name="test" <Grid.RowDeFinitions> <RowDeFinition Height="*"/> <RowDeFinition Height="*"/> <RowDeFinition Height="*"/> </Grid.RowDeFinitions> <controls:MainMenuButton MainMenuFlyout="{Binding ElementName=test}" Grid.Row="0"/> <controls:MainMenuButton MainMenuFlyout="{Binding ElementName=test}" Grid.Row="0"/> <controls:MainMenuButton MainMenuFlyout="{Binding ElementName=test}" Grid.Row="0"/> <controls:MainMenuFlyout /> <Button.Flyout />

C#:

public class MainMenuButton : Button { public static DependencyProperty MainMenuFlyoutProperty = DependencyProperty.Register("MainMenuFlyout",typeof(MainMenuFlyout),typeof(MainMenuButton),new PropertyMetadata(string.Empty,MainMenuFlyoutPropertyChangedCallback)); public static void SetMainMenuFlyout(UIElement element,MainMenuFlyout value) { element.SetValue(MainMenuFlyoutProperty,value); } public MainMenuFlyout GetMainMenuFlyout(UIElement element) { return (MainMenuFlyout)element.GetValue(MainMenuFlyoutProperty); } private static void MainMenuFlyoutPropertyChangedCallback(DependencyObject dependencyObject,DependencyPropertyChangedEventArgs e) { } }

在windows命令行上build立modernizr

为什么通过WMI只应用一次静态IP地址?

Google Chrome框架是否可以在locking的Windows机器上安装?

我如何在C中测量时间?

我可以使用单声道的AOTfunction本地“预编译”.NET DLL / EXE,使他们更难以逆向工程?

依赖项属性声明是错误的。 应该看起来像这样,用一个常规的属性包装而不是静态的getter和setter方法,而null作为认的属性值,而不是string.Empty :

public static DependencyProperty MainMenuFlyoutProperty = DependencyProperty.Register( "MainMenuFlyout",new PropertyMetadata(null,MainMenuFlyoutPropertyChangedCallback)); public MainMenuFlyout MainMenuFlyout { get { return (MainMenuFlyout)GetValue(MainMenuFlyoutProperty); } set { SetValue(MainMenuFlyoutProperty,value); } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐