Wpf InteractionRequestTrigger弹出窗口自定义图标
我正在使用PRISM 5,我正在使用Wpf InteractionRequestTrigger弹出窗口自定义图标,wpf,prism,Wpf,Prism,我正在使用PRISM 5,我正在使用InteractionRequestTrigger和PopupWindowAction显示一个自定义视图 有人知道如何设置对话框窗口的图标吗 我自己找到了答案,解决方案是(我认为)从popupIndowAction派生一个类,该类有一个新图标DependencyProperty。我还添加了一个断言来检查notification.Title是null还是空的,在这种情况下,我将wrapperWindow.Title设置为空字符串 using System.Win
InteractionRequestTrigger
和PopupWindowAction
显示一个自定义视图有人知道如何设置对话框窗口的图标吗 我自己找到了答案,解决方案是(我认为)从popupIndowAction派生一个类,该类有一个新图标
DependencyProperty
。我还添加了一个断言来检查notification.Title是null还是空的,在这种情况下,我将wrapperWindow.Title设置为空字符串
using System.Windows;
using System.Windows.Media;
using Microsoft.Practices.Prism.Interactivity;
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
/// <summary>
/// Shows a popup window with in response to an <see cref="InteractionRequest"/> being raised.
/// </summary>
/// <remarks>
/// This popup window has an Icon property that can be used to set the icon
/// </remarks>
public class IconPopupWindowAction : PopupWindowAction
{
/// <summary>
/// The icon of the child window that is displayed as part of the popup.
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(
"Icon",
typeof(ImageSource),
typeof(IconPopupWindowAction),
new PropertyMetadata(null));
/// <summary>
/// Gets or sets the Icon of the window.
/// </summary>
public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); }
}
/// <summary>
/// Returns the window to display as part of the trigger action.
/// </summary>
/// <param name="notification">The notification to be set as a DataContext in the window.</param>
/// <returns>
/// The popup window
/// </returns>
protected override Window GetWindow(INotification notification)
{
Window wrapperWindow;
if (this.WindowContent != null)
{
wrapperWindow = new Window();
// If the WindowContent does not have its own DataContext, it will inherit this one.
wrapperWindow.DataContext = notification;
if (string.IsNullOrEmpty(notification.Title))
{
wrapperWindow.Title = string.Empty;
}
else
{
wrapperWindow.Title = notification.Title;
}
wrapperWindow.Icon = this.Icon;
this.PrepareContentForWindow(notification, wrapperWindow);
}
else
{
wrapperWindow = this.CreateDefaultWindow(notification);
wrapperWindow.Icon = this.Icon;
}
return wrapperWindow;
}
}
使用System.Windows;
使用System.Windows.Media;
使用Microsoft.Practices.Prism.Interactivity;
使用Microsoft.Practices.Prism.Interactivity.InteractionRequest;
///
///显示一个弹出窗口,其中包含对所引发事件的响应。
///
///
///此弹出窗口具有可用于设置图标的图标属性
///
公共类IconPopupWindowAction:PopupWindowAction
{
///
///作为弹出窗口的一部分显示的子窗口的图标。
///
公共静态只读从属属性IconProperty=
从属属性。寄存器(
“图标”,
类型(图像源),
类型(IconPopupWindowAction),
新属性元数据(空);
///
///获取或设置窗口的图标。
///
公共图像源图标
{
获取{return(ImageSource)this.GetValue(IconProperty);}
set{this.SetValue(IconProperty,value);}
}
///
///返回要作为触发器操作的一部分显示的窗口。
///
///要在窗口中设置为DataContext的通知。
///
///弹出窗口
///
受保护的覆盖窗口GetWindow(INotification通知)
{
窗口包装器窗口;
如果(this.WindowContent!=null)
{
wrapperWindow=新窗口();
//如果WindowContent没有自己的DataContext,它将继承此DataContext。
wrapperWindow.DataContext=通知;
if(string.IsNullOrEmpty(notification.Title))
{
wrapperWindow.Title=string.Empty;
}
其他的
{
wrapperWindow.Title=通知.Title;
}
wrapperWindow.Icon=this.Icon;
此.PrepareContentForWindow(通知,包装窗口);
}
其他的
{
wrapperWindow=this.CreateDefaultWindow(通知);
wrapperWindow.Icon=this.Icon;
}
返回包装器窗口;
}
}
我自己找到了答案,解决方案是(我认为)从PopupWindowAction派生一个类,该类有一个新图标DependencyProperty
。我还添加了一个断言来检查notification.Title是null还是空的,在这种情况下,我将wrapperWindow.Title设置为空字符串
using System.Windows;
using System.Windows.Media;
using Microsoft.Practices.Prism.Interactivity;
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
/// <summary>
/// Shows a popup window with in response to an <see cref="InteractionRequest"/> being raised.
/// </summary>
/// <remarks>
/// This popup window has an Icon property that can be used to set the icon
/// </remarks>
public class IconPopupWindowAction : PopupWindowAction
{
/// <summary>
/// The icon of the child window that is displayed as part of the popup.
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(
"Icon",
typeof(ImageSource),
typeof(IconPopupWindowAction),
new PropertyMetadata(null));
/// <summary>
/// Gets or sets the Icon of the window.
/// </summary>
public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); }
}
/// <summary>
/// Returns the window to display as part of the trigger action.
/// </summary>
/// <param name="notification">The notification to be set as a DataContext in the window.</param>
/// <returns>
/// The popup window
/// </returns>
protected override Window GetWindow(INotification notification)
{
Window wrapperWindow;
if (this.WindowContent != null)
{
wrapperWindow = new Window();
// If the WindowContent does not have its own DataContext, it will inherit this one.
wrapperWindow.DataContext = notification;
if (string.IsNullOrEmpty(notification.Title))
{
wrapperWindow.Title = string.Empty;
}
else
{
wrapperWindow.Title = notification.Title;
}
wrapperWindow.Icon = this.Icon;
this.PrepareContentForWindow(notification, wrapperWindow);
}
else
{
wrapperWindow = this.CreateDefaultWindow(notification);
wrapperWindow.Icon = this.Icon;
}
return wrapperWindow;
}
}
使用System.Windows;
使用System.Windows.Media;
使用Microsoft.Practices.Prism.Interactivity;
使用Microsoft.Practices.Prism.Interactivity.InteractionRequest;
///
///显示一个弹出窗口,其中包含对所引发事件的响应。
///
///
///此弹出窗口具有可用于设置图标的图标属性
///
公共类IconPopupWindowAction:PopupWindowAction
{
///
///作为弹出窗口的一部分显示的子窗口的图标。
///
公共静态只读从属属性IconProperty=
从属属性。寄存器(
“图标”,
类型(图像源),
类型(IconPopupWindowAction),
新属性元数据(空);
///
///获取或设置窗口的图标。
///
公共图像源图标
{
获取{return(ImageSource)this.GetValue(IconProperty);}
set{this.SetValue(IconProperty,value);}
}
///
///返回要作为触发器操作的一部分显示的窗口。
///
///要在窗口中设置为DataContext的通知。
///
///弹出窗口
///
受保护的覆盖窗口GetWindow(INotification通知)
{
窗口包装器窗口;
如果(this.WindowContent!=null)
{
wrapperWindow=新窗口();
//如果WindowContent没有自己的DataContext,它将继承此DataContext。
wrapperWindow.DataContext=通知;
if(string.IsNullOrEmpty(notification.Title))
{
wrapperWindow.Title=string.Empty;
}
其他的
{
wrapperWindow.Title=通知.Title;
}
wrapperWindow.Icon=this.Icon;
此.PrepareContentForWindow(通知,包装窗口);
}
其他的
{
wrapperWindow=this.CreateDefaultWindow(通知);
wrapperWindow.Icon=this.Icon;
}
返回包装器窗口;
}
}
一个非常简单的解决方案是
public class IconPopupWindowAction : PopupWindowAction
{
public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(IconPopupWindowAction), new PropertyMetadata(null));
public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); }
}
protected override Window GetWindow(INotification notification)
{
Window defaultWindow = base.GetWindow(notification);
defaultWindow.Icon = this.Icon;
return defaultWindow;
}
}
这也更好,因为您提供的解决方案是从中复制并粘贴的,但您对其进行了一些修改不幸的是,prism的实现可能会改变,实际上,从您复制它的时候起,它就真的改变了 因此,按照您的方式,您必须更新
IconPopupWindowAction
类以保持与Prism的同步。
这个解决方案更好,因为它不是从Prism库复制代码,而是通过调用base方法base.GetWindow(notification)
来重用它这可以保护您在将Prism更新到新版本时不会破坏Prism代码。一个非常简单的解决方案可能是
public class IconPopupWindowAction : PopupWindowAction
{
public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(IconPopupWindowAction), new PropertyMetadata(null));
public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); }
}
protected override Window GetWindow(INotification notification)
{
Window defaultWindow = base.GetWindow(notification);
defaultWindow.Icon = this.Icon;
return defaultWindow;
}
}
这也更好,因为您提供的解决方案是从中复制并粘贴的,但您对其进行了一些修改不幸的是,prism的实现可能会改变,实际上,从您复制它的时候起,它就真的改变了 所以