FoldFence
FoldFence

Reputation: 2802

How to set Image in Window Title in XAML with MashAPPs.Metro

I have a window and want to set a Picture instead of the title text, but it only shows the String of the Image Namespace.

Code:

<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}">

Picture:

enter image description here

The Icon is shown Correctly and the Image is saved as a BitmapImage.

How can I set a Image in a window title instead of the normal text ?

Upvotes: 1

Views: 954

Answers (2)

FoldFence
FoldFence

Reputation: 2802

I realized it with the LeftWindow Command for the Image and Right Window For the Menu etc..

Code:

<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>

Picture

enter image description here

Upvotes: 0

Nikola.Lukovic
Nikola.Lukovic

Reputation: 1325

Since you're using MahApps controls you need to do it like this:

<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>

You can use an Image control for a visual brush if you need to.

Upvotes: 1

Related Questions