I'm trying to create a WPF menu that consists out of 5 simple buttons that are filled entire with a single image. I've created the following XAML:
<Menu x:Name="menuMain" Height="40" Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<MenuItem x:Name="menuItemPrint" Width="40" Height="40">
<MenuItem.Icon>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuItemClear" Width="40" Height="40">
<MenuItem.Icon>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuItemSettings" Width="40" Height="40">
<MenuItem.Icon>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuItemScanner" Width="40" Height="40">
<MenuItem.Icon>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="menuItemMode" Width="40" Height="40" Click="menuItemMode_Click">
<MenuItem.Icon>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40"/>
</MenuItem.Icon>
</MenuItem>
</Menu>
But the exact result of that is shown below:
It's showing only the top left quarter of the image, and it seems to be offsetting it for some bizarre reason as well? Almost all answers on the internet involve setting the size of the picture, which I did (the .PNG size is exactly 40x40, and so are the MenuItems and Images.
I've tried changing the alignment, setting Fill to 'Stretch' and adjusting the margin, but nothing seems to help.
For the record, what I'm trying the achieve is shown below (Though preferably with a less grotesquely ugly green checkmark. You'll have to excuse my editing skills).
Instead of using the Icon attribute, use the Header and just set a margin offset.
<MenuItem x:Name="menuItemPrint" Width="40" Height="40">
<MenuItem.Header>
<Image Source="Resources/Images/Yes.png" Width="40" Height="40" Margin="-7"/>
</MenuItem.Header>
</MenuItem>
Try overriding the menuitem template. This seems to work for me.
<Menu Height="40">
<MenuItem Height="40" Width="40">
<MenuItem.Template>
<ControlTemplate>
<Image Source="source path here" />
</ControlTempalte>
</MenuItem.Template>
</MenuItem>
</Menu>
Related
I'm trying to right-align a single menu item though a method found here, but applying this method (seen in the code below) moves the menu to the center of the window, and I can't find an elegant solution to move it back to the top.
<DockPanel>
<Menu>
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="File">
<MenuItem Header="Home" Click="MenuItem_Home_Click"/>
<MenuItem Header="About"/>
<MenuItem Header="Settings" Click="MenuItem_Settings_Click"/>
<Separator/>
<MenuItem Header="Exit" Click="MenuItem_Exit_Click"/>
</MenuItem>
<MenuItem Header="Notifications" HorizontalAlignment="Right" FlowDirection="RightToLeft"/>
</Menu>
</DockPanel>
Menu location with code
Don't suppose anyone can work out what I've done wrong here?
I've tried various different methods to fix this, only removing the whole Menu.ItemsPanel code works in returning the menu to it's original location, but that also moves the Notifications menu item to the left.
You need to put it in a container, such as a grid, that restricts it's height.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu Grid.Row="0">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem Header="File">
<MenuItem Header="Home" Click="MenuItem_Home_Click"/>
<MenuItem Header="About"/>
<MenuItem Header="Settings" Click="MenuItem_Settings_Click"/>
<Separator/>
<MenuItem Header="Exit" Click="MenuItem_Exit_Click"/>
</MenuItem>
<MenuItem Header="Notifications" HorizontalAlignment="Right" FlowDirection="RightToLeft"/>
</Menu>
</Grid>
i'm making a simple WPF application and i'm facing a problem.
I have a StackPanel that contain a Menu and a StackPanel and i'm trying to align certains MenuItem to right but with no success...
I trying to do something like that :
===================================================
FILE .....................................................REDUCE MINIMIZE CLOSE --->MENU
APPTITLE ---------------------------------------------> Stackpanel
There is another StackPanel that contain both elements to align them Vertically
I tried differents way, with my menu item in a stackpanel or dockpanel...
Here is my MainWindow.xaml :
<StackPanel Orientation="Vertical">
<Menu materialDesign:RippleAssist.IsDisabled="True" Name="menu" Height="40" Foreground="#FF060000" BorderBrush="#FFED0303">
<MenuItem HorizontalAlignment="Center" VerticalAlignment="Center" Header="_Fichier">
<MenuItem Header="_Quitter" Click="ExitButton_Click">
<MenuItem.Icon>
<Image Source="assets/images/quitter.png"></Image>
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Click="minimize_Click" Height="15" Width="19" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,5">
<MenuItem.Background>
<ImageBrush ImageSource="assets/images/minimize.png"/>
</MenuItem.Background>
</MenuItem>
<MenuItem Click="maximize_Click" Height="15" Width="19" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="11,10,0,0">
<MenuItem.Background>
<ImageBrush x:Name="resizeImage" ImageSource="{Binding ResizeImagePath}"/>
</MenuItem.Background>
</MenuItem>
<MenuItem Click="ExitButton_Click" Height="20" Width="19" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="11,10,0,0">
<MenuItem.Background>
<ImageBrush ImageSource="assets/images/close.png"/>
</MenuItem.Background>
</MenuItem>
</Menu>
<StackPanel Orientation="Horizontal" Margin="0,14,0,0" VerticalAlignment="Center">
<Button Margin="10,0,0,0" Click="scanNetwork_Click" BorderBrush="{x:Null}">
<Button.Background>
<ImageBrush ImageSource="assets/images/756363-200.png"/>
</Button.Background>
</Button>
<TextBlock Text="Machine Sniffer" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="24" FontWeight="Bold" FontFamily="{DynamicResource MaterialDesignFont}" Foreground="White" Margin="10,0,0,0"></TextBlock>
</StackPanel>
</StackPanel>
The actual result is something like that :
===================================================
FILE REDUCE MINIMIZE CLOSE --->MENU
APPTITLE ---------------------------------------------> Stackpanel
Thanks for help
In StackPanel you are not able to adjust items to te right like you are doing, they not allow alignment in the direction in which they stack.
You can use a Grid or a DockPanel instead:
Example with DockPanel:
<DockPanel Width="300">
<!-- place menu items here and use the VerticalAlignment property like you're doing -->
</DockPanel>
Example with Grid:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- place elements here and indicate respective column -->
</Grid>
The text that is in the MenuItem Header is getting a hidden part, as shown in the image below. The full text is "Informações de Pagamento", but the rest is hidden. I need this component to be this size, width =240
My axml file:
<Image.ContextMenu>
<ContextMenu HorizontalAlignment="Left" Width="240">
<MenuItem x:Name="infoPagamento" Header="_Informações de Pagamento" Cursor="Hand" ToolTip="Online" Click="statusOn_Click" Background="White" Margin="5" >
<MenuItem.Icon>
<Image Source="../Imagens/icons/menuusuario/icon_financeiro.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="alteracaoPlano" Header="Alteração de plano" Cursor="Hand" ToolTip="Alteração de plano" Click="statusAusente_Click" Background="White" Margin="5">
<MenuItem.Icon>
<Image Source="../Imagens/icons/menuusuario/icon_tarefa.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="Relatorios" Header="Relatórios" Cursor="Hand" ToolTip="Ocupado" Click="statusOcupado_Click" Background="White" Margin="5">
<MenuItem.Icon>
<Image Source="../Imagens/icons/menuusuario/icon_relatorios.png" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem x:Name="Ajuda" Header="Ajuda" Cursor="Hand" ToolTip="Offline" Click="statusOff_Click" Background="White" Margin="5">
<MenuItem.Icon>
<Grid>
<Ellipse Width="20" Height="20" Fill="#48026E" />
<Label Content="?" Padding="0"
VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="White" FontSize="14" Cursor="Hand"/>
</Grid>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</Image.ContextMenu>
My Resource:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border"
Background="White"
BorderThickness="1" BorderBrush="Transparent"
Margin="3" CornerRadius="10">
<StackPanel IsItemsHost="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I had similar problem for Menu with drop down style. The problem is in reserved space for shortcut like CTRL+D (input gesture text). To overcome limitation I had to set menu item width to fixed size, override menuitem header with text block, set its width to auto (fixed width did not work like expected) and set negative margin for textblock (its size can be different for your problem).
Some short example:
<Menu IsMainMenu="True" Height="auto" Width="220" Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Center" HorizontalContentAlignment="Stretch">
<MenuItem BorderThickness="0" Width="220" Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch">
<MenuItem.Icon>
<Ellipse Width="25" Height="25" HorizontalAlignment="Center" Stretch="Uniform">
<Ellipse.Fill>
<ImageBrush x:Name="imgAvatar" ImageSource="..." TileMode="Tile" Stretch="UniformToFill" />
</Ellipse.Fill>
</Ellipse>
</MenuItem.Icon>
<MenuItem.Header>
<TextBlock Text="Some long long text" Width="auto" TextWrapping="Wrap" Margin="0,0,-75,0" VerticalAlignment="Center" TextAlignment="Left" HorizontalAlignment="Left"/>
</MenuItem.Header>
<MenuItem BorderThickness="0" Width="220" Margin="0" VerticalAlignment="Center" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch">
<MenuItem.Icon>
<Ellipse Width="25" Height="25" HorizontalAlignment="Center" Stretch="Uniform">
<Ellipse.Fill>
<ImageBrush x:Name="imgAvatar" ImageSource="..." TileMode="Tile" Stretch="UniformToFill" />
</Ellipse.Fill>
</Ellipse>
</MenuItem.Icon>
<MenuItem.Header>
<TextBlock Text="Some long long text 2" Width="auto" TextWrapping="Wrap" Margin="0,0,-75,0" VerticalAlignment="Center" TextAlignment="Left" HorizontalAlignment="Left"/>
</MenuItem.Header>
</MenuItem>
</MenuItem>
</Menu>
Try setting the width of MenuItem as "Auto"
I'm developing a border less WPF window application with MahApps.Metro control.
I want to have my menu where normally the window title goes (Title bar's left side). Like below image:
What I have got so far looks like below image:
I have tried setting HorizontalAlignment="Left", but the menu group remains on the right side of the title bar.
Code for this:
<Controls:MetroWindow.WindowCommands>
<Controls:WindowCommands HorizontalAlignment="Left">
<Menu IsMainMenu="True" x:Name="mnuMainMenu" Height="28" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" Background="Transparent" Width="Auto" >
<MenuItem Header="_File" x:Name="mnuFile" Visibility="Visible" Background="Transparent">
<MenuItem Header="_Open" x:Name="mnuOpen" Background="Transparent" Command="{Binding MenuOpenCommand}" />
<MenuItem Header="_Exit" x:Name="mnuExit" Click="btnExit_Click" Background="Transparent"/>
</MenuItem>
<MenuItem Header="_Tools">
<MenuItem Header="_Repeat" x:Name="mnuRepete" Background="Transparent" >
<MenuItem Header="Repeat None" Command="{Binding RepeatNoneCommand}" IsCheckable="True"/>
<MenuItem Header="Repeat One" Command="{Binding RepeatOneCommand}" IsCheckable="True"/>
<MenuItem Header="Repeat All" Command="{Binding RepeatAllCommand}" IsCheckable="True"/>
</MenuItem>
</MenuItem>
<MenuItem Header="_Store" x:Name="smOnlineMode" Background="Transparent" Click="smOnlineMode_Click" IsCheckable="True" />
<MenuItem Header="_Play Mode" x:Name="smPlayMode" Background="Transparent" Click="smPlayMode_Click" IsCheckable="True" IsChecked="True"/>
<MenuItem Header="_Play">
<MenuItem Header="_Play" x:Name="mnuPlay" Background="Transparent" Command="{Binding PlayCommand}"/>
<MenuItem Header="P_ause" x:Name="mnuPause" Background="Transparent" Command="{Binding PauseCommand}"/>
<MenuItem Header="_Stop" x:Name="mnuStop" Background="Transparent" Command="{Binding StopCommand}"/>
<Separator/>
<MenuItem Header="_Next" x:Name="mnuNext" Background="Transparent" Command="{Binding NextTrackCommand}"/>
<MenuItem Header="P_revious" x:Name="mnuPrevious" Background="Transparent" Command="{Binding PreviousTrackCommand}" />
<MenuItem Header="_Mute/UnMute" x:Name="smnuMute" Background="Transparent" Command="{Binding MuteSoundCommand}" />
<!--Command="{Binding MuteSoundCommand}"-->
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_Help" x:Name="smnuOnlineHelp" Background="Transparent" Click="smnuHelp_Click" />
<Separator />
<MenuItem Header="_Register Player" x:Name="smnuRegister" Background="Transparent" Click="smnuRegisterPlayer" />
<MenuItem Header="_About Codero Music Player" x:Name="smnuAbout" Background="Transparent" Click="smnuAboutClick" />
</MenuItem>
</Menu>
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>
You can do something like this
Remove the title from the title bar
Add a MetroWindow.LeftWindowCommands tag
Add windows command tag inside LeftWindowCommands
Place a stackpanel or grid and place what ever you want in the title bar
Code:
<controls:MetroWindow.LeftWindowCommands>
<controls:WindowCommands>
<StackPanel Name="menuHolder" Orientation="Horizontal">
<TextBlock Padding="10,5,10,5" Text="My Window"></TextBlock>
<Menu Name="mymenu" Margin="0,5,0,0">
<MenuItem Name="File" Header="File">
<MenuItem Name="Open" Header="Open"/>
<MenuItem Name="Close" Header="Close"/>
</MenuItem>
<MenuItem Name="Edit" Header="Edit">
<MenuItem Name="Copy" Header="Copy"/>
<MenuItem Name="Paste" Header="Paste"/>
</MenuItem>
</Menu>
</StackPanel>
</controls:WindowCommands>
The solution that works for me in MahApps.Metro 1.6.5 is to bind the TitleTemplate dependency property with the MenuBar and Title Textblock in the Main Window as shown below:
MainWindow.xaml:
<Controls:MetroWindow
x:Class="MahAppsMetroDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MahAppsMetroDemo"
mc:Ignorable="d"
Title="ILSpy"
Height="450" Width="800"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Icon="/MahAppsMetroDemo;component/Resources/ILSpy.ico"
>
<Controls:MetroWindow.TitleTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Menu
Grid.Column="0"
Margin="6,0">
<MenuItem Name="File" Header="File">
<MenuItem Name="Open" Header="Open"/>
<MenuItem Name="Close" Header="Close"/>
</MenuItem>
<MenuItem Name="Edit" Header="Edit">
<MenuItem Name="Copy" Header="Copy"/>
<MenuItem Name="Paste" Header="Paste"/>
</MenuItem>
</Menu>
<TextBlock
Grid.Column="1"
Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:MetroWindow}},Path=Title}"
HorizontalAlignment="Left" VerticalAlignment="Center"
Padding="10,5,10,5"
Margin="6,0"
FontSize="16"
FontWeight="Bold"
/>
</Grid>
</DataTemplate>
</Controls:MetroWindow.TitleTemplate>
<Grid>
</Grid>
</Controls:MetroWindow>
MainWindow.cs
namespace MahAppsMetroDemo
{
using MahApps.Metro.Controls;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
}
}
}
Create StackPanel, put your menu into StackPanel and set the property HorizontalAlignment=Left or try to use Margin property again
You have to restyle the MetroWindow for your own. The easiest way for your needs would be to create a custom resource dictionary and copy the MetroWindow.xaml into it and change following line to Grid.Column="0":
MetroWindow.xaml
But do not forget to load that modified resource in App.xaml.
I would like to draw some text on a WriteableBitmap. This doesn't seem possible, but I found converting WriteableBitmap to Bitmap in C# here and this.
Here's the call (with conversion method included, too):
// Draw dino names...
Graphics g = Graphics.FromImage(BitmapFromWriteableBitmap(writeableBitmap));
g.DrawString(Dinosaurs[i].PersonalName, new Font("Tahoma", 40), System.Drawing.Brushes.White, new PointF((float)Dinosaurs[i].Head.X, (float)Dinosaurs[i].Head.Y));
} // for i
}// DrawDinos2d
private System.Drawing.Bitmap BitmapFromWriteableBitmap(WriteableBitmap writeBmp)
{
System.Drawing.Bitmap bmp;
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create((BitmapSource)writeBmp));
enc.Save(outStream);
bmp = new System.Drawing.Bitmap(outStream);
}
return bmp;
}
I've checked in the debugger and g has a good values (not null) but nothing is drawing on the screen. I should also mention that the string that is being passed to DrawString is good and the X,Y of the point is good (positive integers about 1000,800). I think it's either drawing off the screen or maybe the X,Y coordinates aren't translating correctly.
Any ideas? Thanks.
Here's the XAML (if this helps):
<Window x:Class="DinosaurIsland.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Dinosaur Island" Height="600" Width="600" WindowState="Normal" Icon="/DinosaurIsland;component/Icon1.ico" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" WindowStartupLocation="CenterOwner">
<Window.Resources>
<ResourceDictionary>
<DataTemplate DataType="{x:Type BitmapImage}">
<Image Source="{Binding}" />
</DataTemplate>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<DockPanel>
<Menu x:Name="MainMenu" DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_Open Dinosaur Island 'snapshot' file..." x:Name="OpenSnapshotFile" Click="OpenSnapshotFile_click" />
<MenuItem Header="_Save"/>
<MenuItem Header="_Exit" x:Name="ExitApp" Click="ExitAppClick" />
</MenuItem>
<MenuItem Header="_Height Map">
<MenuItem Header="Load Height Map..." Name="LoadHeightMap" Click="LoadHeightMapClick" />
<Separator />
<MenuItem Header="Display Height Map" x:Name="DisplayHeightMap" Click="DisplayHeightMapClick" />
</MenuItem>
<MenuItem Header="Terrain">
<MenuItem Header="Load Terrain Map..." x:Name="LoadTerrainMap" Click="LoadTerrainMap_Click" />
<MenuItem Header="Draw Terrain..." x:Name="DrawTerrain" Click="DisplayTerrainPaintBoxClick" />
<MenuItem Header="Save Terrain Map..." x:Name="SaveTerrainMap" Click="SaveTerrainMap_Click"/>
<MenuItem Header="Get Terrain Data From BMP..." x:Name="TerrainFromBMP" Click="TerrainFromBMP_Click" />
<Separator />
<MenuItem Header="Adjust Terrain Transparency..." x:Name="AdjustTerrainTransparency" Click="AdjustTerrainTransparency_Click"/>
<MenuItem Header="Display Terrain Map" x:Name="DisplayTerrainMap" Click="DisplayTerrainMap_Click"/>
</MenuItem>
<MenuItem Header="_Vegetation">
<MenuItem Header="Plant Vegetation..." x:Name="PlantVegetation" Click="PlantVegetation_Click" />
<Separator />
<MenuItem Header="Load Vegetation Map..." x:Name="LoadVegetation" Click="LoadVegetation_Click" />
<MenuItem Header="Save Vegetation Map..." x:Name="SaveVegetation" Click="SaveVegetation_Click" />
<Separator />
<MenuItem Header="Display Vegetation" Click="DisplayVegetation_Click" />
</MenuItem>
<MenuItem Header="Dinosaurs">
<MenuItem Header="Edit / Place Dinosaurs..." x:Name="EditDinosaurs" Click="EditDinosaurs_Click" />
<Separator />
<MenuItem Header="Load Dinosaur Map" Name="LoadDinosaurnMap" Click="LoadDinosaurs_Click"/>
<MenuItem Header="Save Dinosaur Map" Name="SaveDinosaurMap" Click="SaveDinosaurs_Click"/>
<Separator />
<MenuItem Header="Terrain/Slope Effect..." Name="TerrainSlope" Click="TerrainSlope_Click"/>
<MenuItem Header="Probability of Smelling Dinosaur..." Name="SmellProbability" Click="SmellProbability_Click"/>
</MenuItem>
<MenuItem Header="Time">
<MenuItem Header="Start..." x:Name="AdvanceTime" Click="StartTime_Click" />
<MenuItem Header="Stop..." x:Name="StopTime" Click="StopTime_Click" />
<Separator />
<MenuItem Header="Adjust Time Step..." x:Name="AdjustTimeStep" Click="AdjustTimeStep_Click"/>
</MenuItem>
<MenuItem Header="Debug">
<MenuItem Header="A* trace" Name="AStarTrace" Click="AStarTrace_Click" />
<MenuItem Header="Show Dinosaur Goals" Name="DinoGoals" Click="DinoGoals_Click" />
<MenuItem Header="Show Dinosaur Path" Name="DinoPath" IsChecked="False" Click="DinoPath_Click" />
<MenuItem Header="Show Predator Scent Path" Name="StinkPath" IsChecked="False" Click="StinkPath_Click" />
<MenuItem Header="Show Dinosaur Vision Angles" Name="VisionAngles" IsChecked="True" Click="VisionAngles_Click" />
<MenuItem Header="Show Dinosaur Axis" Name="DinoAxis" IsChecked="True" Click="DinoAxis_Click" />
</MenuItem>
<MenuItem Header="Help">
<MenuItem Header="About Dinosaur Island" Name="AboutDinosaurIsland" Click="AboutDinoIslandClick" />
</MenuItem>
</Menu>
<StatusBar DockPanel.Dock="Bottom">
<TextBlock Name="StatusBarField1">Location = X,Y</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField2">Elevation = X</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField3">Terrain = None</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField4">Plants = None</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField5">Dinosaurs = None</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField6">Zoom</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField7">Time 0:00</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField8">Wind direction: 000</TextBlock>
<Separator/>
<TextBlock Name="StatusBarField9">Speed: 000</TextBlock>
</StatusBar>
<Label DockPanel.Dock="Bottom" Content="Scale = 2000 meters" Height="23" HorizontalAlignment="Center" Name="HorizScaleDisplayText" Width="127" />
<Label DockPanel.Dock="Bottom" Content="└───────────────────────────────┴───────────────────────────────────┘" Height="20" HorizontalAlignment="Center" Name="HorizScaleDisplayLine" Width="423" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Slider Grid.Column="0" Orientation="Vertical" HorizontalAlignment="Left" Minimum="1" x:Name="slider"/>
<ScrollViewer Name="scrollViewer" Grid.Column="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" Margin="0,0,0,6">
<Grid Name="grid" Width="400" Height="400" RenderTransformOrigin="0.5,0.5">
<Grid.RowDefinitions>
<RowDefinition Height="37*" />
<RowDefinition Height="363*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="297*" />
<ColumnDefinition Width="103*" />
</Grid.ColumnDefinitions>
<Grid.LayoutTransform>
<TransformGroup>
<ScaleTransform x:Name="scaleTransform"/>
</TransformGroup>
</Grid.LayoutTransform>
<Viewbox x:Name="viewBox" Margin="-35,-12,-22,22" Grid.ColumnSpan="2" Grid.RowSpan="2">
<ContentPresenter x:Name="contentPresenter" Width="350" Height="350" >
<ContentPresenter.Content>
<Image x:Name="image" Width="350" Height="350">
<Image.Source >
<BitmapImage x:Name="HeightMapImage" UriSource="DinoIslandLogo.bmp" />
</Image.Source>
</Image>
</ContentPresenter.Content>
</ContentPresenter>
</Viewbox>
</Grid>
</ScrollViewer>
</Grid>
</DockPanel>
And this is how I display the bitmap:
this.image.Source = writeableBitmap;
This solved the problem:
public void DrawDinoNames()
{
System.Drawing.Bitmap bmp;
bmp = BitmapFromWriteableBitmap(writeableBitmap);
Graphics g = Graphics.FromImage(bmp);
for (int i = 0; i < Dinosaurs.Count; i++)
{
g.DrawString(Dinosaurs[i].PersonalName, new Font("Tahoma", 14), System.Drawing.Brushes.White, new PointF((float)Dinosaurs[i].Head.X, (float)Dinosaurs[i].Head.Y));
}
this.image.Source = BitmapToImageSource(bmp, System.Drawing.Imaging.ImageFormat.Bmp);
}