我在 wpf 应用程序中使用 AvalonDock 并尝试为此动态设置 layoutAchorableItem 的 IconSource 我喜欢使用 ToolIconSelector 它将返回 vectorIcon 作为 ControlTemplate 但问题是 IconSource 必须是 ImageSource 类型。有谁知道我如何将我的 VectorIcons 用于 AvalonDock 中的 IconSource?
XAML 代码:
<local:PanesStyleSelector x:Key="PanesStyleSelector">
<local:PanesStyleSelector.ToolStyle>
<!--Style definition for the Anchorable Items-->
<Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}">
<Setter Property="Title"
Value="{Binding Model.Name}" />
<Setter Property="CloseCommand"
Value="{Binding Model.CloseCommand}" />
<Setter Property="IconSource"
Value="{Binding Model.IconSource}" />
<Setter Property="Visibility"
Value="{Binding Model.IsVisible, ConverterParameter={x:Static Visibility.Hidden},
Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
<Setter Property="ContentId"
Value="{Binding Model.ContentId}" />
<Setter Property="IsSelected"
Value="{Binding Model.IsSelected, Mode=TwoWay}" />
<Setter Property="IsActive"
Value="{Binding Model.IsActive, Mode=TwoWay}" />
<Setter Property="CanFloat"
Value="{Binding Model.CanFloat, Mode=OneWay}" />
<Setter Property="CanHide"
Value="{Binding Model.CanFloat, Mode=OneWay}" />
<Setter Property="CanClose"
Value="{Binding Model.CanFloat, Mode=OneWay}" />
</Style>
</local:PanesStyleSelector.ToolStyle>
基本上,我想要 IconSource 属性中的值,如上面从 VectorIcon 资源中设置的代码,如下例所示:
<ControlTemplate x:Key="MovieSuiteIcon">
<Viewbox>
<Canvas Width="10240" Height="10240">
<Path Data="M8119 6400l1801 0 0 2560 -4158 0c215,-90 421,-197 616,-320l22 0 0 -14c110,-71 217,-146 320,-227l0 241 320 0 0 -320 -222 0c513,-426 921,-973 1182,-1598l0 318 320 0 0 -320 -319 0c44,-105 83,-211 118,-320zm-759 1920l0 320 320 0 0 -320 -320 0zm640 0l0 320 320 0 0 -320 -320 0zm640 0l0 320 320 0 0 -320 -320 0zm640 0l0 320 320 0 0 -320 -320 0zm-640 -1600l0 320 320 0 0 -320 -320 0zm640 0l0 320 320 0 0 -320 -320 0z
M5358 7314l-595 -820c-76,-105 -200,-152 -327,-124 -181,40 -371,40 -552,0 -127,-28 -251,19 -327,124l-595 820c-60,82 -77,179 -48,277 28,99 94,171 190,209 676,265 1436,265 2112,0 96,-38 162,-110 190,-209 29,-98 12,-195 -48,-277zm-2302 -1546c-94,-160 -152,-338 -170,-523 -12,-130 -96,-234 -220,-274l-963 -313c-97,-31 -194,-17 -279,40 -84,58 -133,143 -139,245 -44,728 188,1446 653,2010 66,79 155,119 257,116 102,-3 189,-49 249,-132l595 -819c77,-105 83,-238 17,-350zm146 -1497c123,-138 275,-250 446,-324 119,-53 192,-164 192,-294l0 -1012c0,-103 -43,-191 -124,-253 -81,-63 -177,-83 -276,-57 -715,184 -1323,636 -1710,1242 -55,86 -66,184 -31,280 34,97 105,165 202,197l963 313c124,40 252,5 338,-92zm1470 -324c171,74 323,186 446,324 86,97 214,132 338,92l963 -313c97,-32 168,-100 202,-197 35,-96 24,-194 -31,-280 -387,-606 -995,-1058 -1710,-1242 -99,-26 -195,-6 -276,57 -81,62 -124,150 -124,253l0 1012c0,130 73,241 192,294zm1709 3006c466,-564 698,-1282 654,-2010 -6,-102 -55,-187 -139,-245 -85,-57 -182,-71 -279,-40l-963 313c-124,40 -208,144 -220,274 -18,185 -76,363 -170,523 -66,112 -60,245 17,350l595 819c60,83 147,129 249,132 102,3 191,-37 256,-116z
M4160 1600c1944,0 3520,1576 3520,3520 0,1944 -1576,3520 -3520,3520 -1944,0 -3520,-1576 -3520,-3520 0,-1944 1576,-3520 3520,-3520zm0 3200c177,0 320,143 320,320 0,177 -143,320 -320,320 -177,0 -320,-143 -320,-320 0,-177 143,-320 320,-320zm0 -320c-353,0 -640,287 -640,640 0,353 287,640 640,640 353,0 640,-287 640,-640 0,-353 -287,-640 -640,-640zm0 -3200c-2121,0 -3840,1719 -3840,3840 0,2121 1719,3840 3840,3840 2121,0 3840,-1719 3840,-3840 0,-2121 -1719,-3840 -3840,-3840z" Fill="{TemplateBinding Foreground}"/>
</Canvas>
</Viewbox>
</ControlTemplate>
有没有办法将其转换为 ImageSource?
提前致谢。凯文