在 XAML 中设置窗口属性的位置
我找到了一些附加属性的代码,可以让我逃脱关闭称为对话框的窗口 这里就这样。
但我不知道在哪里设置该属性。
这可能会因为这是一个 RibbonWindow 而不是普通窗口而变得复杂,但我不这么认为。
附加属性将为 ab:WindowService.EscapeCloseWindow="True"。它应该放在xaml中的哪里?
干杯,
Berryl
错误
Unable to cast object of type
'Microsoft.Expression.Platform.WPF.InstanceBuilders.WindowInstance' to type
'Microsoft.Windows.Controls.Ribbon.RibbonWindow'.
at AttachedBehaviors.WindowService.OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
附加属性的要点是
private static void OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var target = (Window) d;
if (target != null)
target.PreviewKeyDown += Window_PreviewKeyDown;
}
/// <summary>Handle the PreviewKeyDown event on the window</summary>
private static void Window_PreviewKeyDown(object sender, KeyEventArgs e) {
var target = (Window) sender;
// If this is the escape key, close the window
if (e.Key == Key.Escape)
target.Close();
}
window xaml
<r:RibbonWindow x:Class="SCA.Presentation.Wpf.Views.TimeSheet.WeeklyTimeSheetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local ="clr-namespace:SCA.Presentation.Wpf.Views.TimeSheet"
xmlns:ab="clr-namespace:SCA.Presentation.Wpf.AttachedBehaviors;assembly=Smack.Core.Presentation.Wpf"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Background="{DynamicResource WaveWindowBackground}"
FontFamily="Arial" FontSize="12"
Width="900" Height="600"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen"
ab:WindowService.EscapeClosesWindow="True" <=== ERROR
>
<r:RibbonWindow.Resources>
<ResourceDictionary Source="TimesheetResources.xaml" />
</r:RibbonWindow.Resources>
I found some code for an attached property that will let me escape close a window called as a dialog here on SO.
But I can't figure out where to set the property.
This might be complicated by the fact that this is a RibbonWindow and not a normal Window but I don't think so.
The attached property will be ab:WindowService.EscapeClosesWindow="True". Where in the xaml should it go??
Cheers,
Berryl
ERROR
Unable to cast object of type
'Microsoft.Expression.Platform.WPF.InstanceBuilders.WindowInstance' to type
'Microsoft.Windows.Controls.Ribbon.RibbonWindow'.
at AttachedBehaviors.WindowService.OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
The gist of the attached property is
private static void OnEscapeClosesWindowChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
var target = (Window) d;
if (target != null)
target.PreviewKeyDown += Window_PreviewKeyDown;
}
/// <summary>Handle the PreviewKeyDown event on the window</summary>
private static void Window_PreviewKeyDown(object sender, KeyEventArgs e) {
var target = (Window) sender;
// If this is the escape key, close the window
if (e.Key == Key.Escape)
target.Close();
}
window xaml
<r:RibbonWindow x:Class="SCA.Presentation.Wpf.Views.TimeSheet.WeeklyTimeSheetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local ="clr-namespace:SCA.Presentation.Wpf.Views.TimeSheet"
xmlns:ab="clr-namespace:SCA.Presentation.Wpf.AttachedBehaviors;assembly=Smack.Core.Presentation.Wpf"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Background="{DynamicResource WaveWindowBackground}"
FontFamily="Arial" FontSize="12"
Width="900" Height="600"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen"
ab:WindowService.EscapeClosesWindow="True" <=== ERROR
>
<r:RibbonWindow.Resources>
<ResourceDictionary Source="TimesheetResources.xaml" />
</r:RibbonWindow.Resources>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个示例应用程序来重现您提到的错误。我未能重现该错误。它很容易在我的应用程序中编译。
您可以检查示例应用程序并尝试找出任何差异吗?
娱乐:
XAML:
I created a sample application to recreate that error you mentioned. And I failed to reproduce that error. It easily compiled in my app.
Can you check with a sample application and try to find any differences?
Recreation:
XAML: