圖像選擇器
集成到Visual Studio中的DevExpress圖像選擇器對(duì)話框允許您為 WPF 控件配置圖像,此對(duì)話框適用于.NET/.NET Core和 .NET Framework。圖像選擇器顯示添加到解決方案的光柵和矢量DevExpress圖標(biāo)和圖像的集合。
調(diào)用圖像選擇器
在Visual Studio中,打開(kāi)Extensions工具欄菜單,選擇DevExpress, WPF Controls v23.1,然后單擊Run Image Picker。
也可以從以下路徑運(yùn)行Image Picker:
DevExpress 23.1 Installation Folder\Components\Tools\Components Tools\ImagePicker.v21.2.exe
DevExpress WPF控件的默認(rèn)安裝路徑如下:
C:\Program Files\DevExpress 23.1\
在設(shè)計(jì)時(shí)配置圖像
使用智能標(biāo)簽面板或快速操作來(lái)調(diào)用DevExpress控件的圖像屬性的Image Picker,例如字形或圖標(biāo)。 Image Picker顯示來(lái)自以下來(lái)源的圖像:
- DevExpress.Images NuGet 包或DevExpress.Images.v23.1.dll程序集。
- 應(yīng)用程序的解決方案。
從image Picker中選擇一個(gè)圖像,然后單擊OK來(lái)分配它。
當(dāng)您從.NET Framework項(xiàng)目中的Quick Actions調(diào)用Image Picker,并且您的解決方案缺少對(duì)DevExpress.Images.v23.1.dll的引用時(shí),Image Picker僅顯示解決方案中包含的圖像。
單擊添加Add the DevExpress.Images assembly鏈接來(lái)使用DevExpress圖標(biāo)集合填充Image Picker 。
您可以在獨(dú)立模式下啟動(dòng)Image Picker,為此單擊Visual Studio DevExpress菜單中的Run Image Picker項(xiàng),或者運(yùn)行位于DevExpress安裝文件夾中的可執(zhí)行文件ImagePicker.v23.1.exe。默認(rèn)路徑為“C:\Program Files\DevExpress 23.1\Components\Tools\Components Tools\ImagePicker.v23.1.exe”。
在這個(gè)場(chǎng)景中,圖像選擇器顯示了柵格和矢量DevExpress圖像的集合:
獨(dú)立的圖像選取器用System.Uri和DXImage格式顯示所選圖像的路徑,您可以使用路徑在標(biāo)記中指定圖像。下面的代碼示例演示了如何用DXImage格式設(shè)置BarButtonItem.Glyph和BarButtonItem.LargeGlyph屬性:
<dxr:RibbonControl> <dxr:RibbonDefaultPageCategory> <dxr:RibbonPage Caption="Home"> <dxr:RibbonPageGroup> <dxb:BarButtonItem Content="Open" Glyph="{dx:DXImage Image=Open_16x16.png}" LargeGlyph="{dx:DXImage Image=Open_32x32.png}" RibbonStyle="Large"/> <dxb:BarButtonItem Content="New" Glyph="{dx:DXImage Image=New_16x16.png}" LargeGlyph="{dx:DXImage Image=New_32x32.png}" RibbonStyle="Large"/> </dxr:RibbonPageGroup> </dxr:RibbonPage> </dxr:RibbonDefaultPageCategory> </dxr:RibbonControl>
下圖顯示了結(jié)果:
在代碼中指定圖像
使用以下方法在代碼中從Image Picker中獲取圖像:
下面的代碼示例演示了如何在代碼隱藏中指定圖像:
C#:
BarButtonItem bOpen = new BarButtonItem { Content = "Open", Glyph = DXImageHelper.GetImageSource("Open", ImageSize.Size16x16), LargeGlyph = DXImageHelper.GetImageSource("Open", ImageSize.Size32x32), RibbonStyle = RibbonItemStyles.Large }; BarButtonItem bNew = new BarButtonItem { Content = "New", Glyph = DXImageHelper.GetImageSource("New", ImageSize.Size16x16), LargeGlyph = DXImageHelper.GetImageSource("New", ImageSize.Size32x32), RibbonStyle = RibbonItemStyles.Large };
VB.NET:
Private bOpen As BarButtonItem = New BarButtonItem With { .Content = "Open", .Glyph = DXImageHelper.GetImageSource("Open", ImageSize.Size16x16), .LargeGlyph = DXImageHelper.GetImageSource("Open", ImageSize.Size32x32), .RibbonStyle = RibbonItemStyles.Large } Private bNew As BarButtonItem = New BarButtonItem With { .Content = "New", .Glyph = DXImageHelper.GetImageSource("New", ImageSize.Size16x16), .LargeGlyph = DXImageHelper.GetImageSource("New", ImageSize.Size32x32), .RibbonStyle = RibbonItemStyles.Large }
只有當(dāng)該圖像存在于所有圖像集中時(shí),才能使用DXImageHelper.GetImageSource方法通過(guò)其ID獲取該圖像。