2016-03-07 95 views
1

我有一個窗口,並且想要設置圖片而不是標題文本,但它只顯示圖像名稱空間的字符串。如何使用MashAPPs.Metro在XAML中的窗口標題中設置圖像

代碼:

<Controls:MetroWindow x:Class="AdminControlCenter.View.MainView" 
    ... 
    Title="{Binding ImageViewModel.TitleBarImage}" Height="400" Width="600" 
    mc:Ignorable="d" 
    d:DataContext="{d:DesignInstance vm:MainViewModel}" Icon="{Binding ImageViewModel.Icon}"> 

圖片:

enter image description here

圖標顯示正確並且圖像被保存爲一個的BitmapImage。

如何在窗口標題中設置圖像而不是普通文本?

+0

取而代之的是,爲什麼不要將圖像存儲在應用程序根文件夾中,並指定圖像的路徑。 – VVN

+0

我使用MVVM模式製作程序 – SeeuD1

+0

窗口圖標對於所有窗口都是通用的嗎?那麼,爲什麼要使用MVVM模式?只需指定圖標的路徑即可。 – VVN

回答

0

我與LeftWindow命令的圖像和右眼窗口菜單等實現它..

代碼:

<Controls:MetroWindow.LeftWindowCommands> 
<Controls:WindowCommands> 
    <Image Source="{Binding ImageViewModel.TitleBarImage}"/> 
</Controls:WindowCommands> 
</Controls:MetroWindow.LeftWindowCommands> 

<Controls:MetroWindow.RightWindowCommands> 
    <Controls:WindowCommands> 
     <VisualBrush Stretch="Fill"/> 
     <StackPanel Name="menuHolder" Orientation="Horizontal"> 
      <Menu Name="MenuBar"> 
       <MenuItem Name="Options" Header="Options" > 
        <MenuItem Name="Settings" Header="Settings"/> 
        <MenuItem Name="Close" Header="Close"/> 
       </MenuItem> 
      </Menu> 
     </StackPanel> 
    </Controls:WindowCommands> 
</Controls:MetroWindow.RightWindowCommands> 

圖片

enter image description here

1

由於您使用MahApps控制你需要做的是這樣的:

<Controls:MetroWindow.IconTemplate> 
    <DataTemplate> 
     <Grid Width="{TemplateBinding Width}" 
       Height="{TemplateBinding Height}" 
       Margin="8 8 0 8" 
       Background="Transparent" 
       RenderOptions.EdgeMode="Aliased" 
       RenderOptions.BitmapScalingMode="HighQuality"> 
      <Rectangle Fill="White"> 
       <Rectangle.OpacityMask> 
        <VisualBrush Visual="{StaticResource appbar_resource_group}" Stretch="Uniform"/> 
       </Rectangle.OpacityMask> 
      </Rectangle> 
     </Grid> 
    </DataTemplate> 
</Controls:MetroWindow.IconTemplate> 

如果需要,您可以使用Image控件的視覺刷。

相關問題