<Style x:Key="Base" TargetType="MenuItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}" x:Name = "customControl">
<Border Name="FastBorder" Height="22" Width="200">
<Grid>
<Image Name="Fast" Width="15" Height="15" HorizontalAlignment="Stretch" Margin="0,0,170,0" Source="{Binding IMGFast}"/>
<TextBlock Name="TextOP" Text="Быстрое удаление проекта" FontSize="12" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="30,4,0,0" Width="200" Height="25" Foreground="Lime" Background="{Binding BackColorFast}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Image Name="Fast" Width="15" Height="15" HorizontalAlignment="Stretch" Margin="0,0,170,0" Source="{Binding IMGFast}"/>
Source="{Binding IMGFast}"/>
DataContext = new MainWindow[]
{
new MainWindow
{
IMGFast ="ok.png",
BackColorFast = "#25FFFFFF",
IMGFull ="",
BackColorFull = ""
}
};
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<BitmapImage x:Key="MyImageSource" UriSource="H:\Temp\WpfApplication1\WpfApplication1\bin\Debug\icon1.png" />
</Application.Resources>
</Application>
<Window x:Class="WpfApplication1.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:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Name="Fast" Width="15" Height="15" HorizontalAlignment="Stretch" Margin="0,0,170,0" Source="{DynamicResource MyImageSource}"/>
<Button Name="button" Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Media.Imaging;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Resources["MyImageSource"] =
new BitmapImage(new Uri(@"H:\Temp\WpfApplication1\WpfApplication1\bin\Debug\icon2.png"));
}
}
}
#region Класс загрузки изображения в меню
public class Images
{
public string IMGFast { get; set; }
public string IMGFull { get; set; }
public string BackColorFast { get; set; }
public string BackColorFull { get; set; }
}
#endregion
DataContext = new Images[]
{
new Images
{
IMGFast ="ok.png",
BackColorFast = "#25FFFFFF",
IMGFull ="",
BackColorFull = ""
}
};