how can i copy my first image in first layout and display to another layout?

Viewed 38
private void BtnCar1_Click(object sender, RoutedEventArgs e)
{
    CarDisplay cardisplay = new CarDisplay();
    cardisplay.LblCarName1.Content = "HONDA XCX 2014V";
    cardisplay.FuelType.Content = "CRUDE";
    cardisplay.NoOfCylinder.Content = "5";
    cardisplay.TransmissionType.Content = "AUTOMATIC";
    cardisplay.SeatingCapacity.Content = "6";
    cardisplay.Price.Content = "P800,000";
    
    cardisplay.Show();
}
1 Answers

In WPF you can create a shared ResourceDictionary where you define the image sources.

So your ResourceDictionary.xaml could look like:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <BitmapImage x:Key="TestImg" UriSource="/test.png" />
</ResourceDictionary>

You can define to access in the Window.Resources area of your window, and than use the Source like shown in the sample:

<Window x:Class="WpfTestApp2.Window1"
        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:WpfTestApp2"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">
    <Window.Resources>
        <ResourceDictionary Source="ResourceDictionary.xaml"></ResourceDictionary>
    </Window.Resources>
    <Grid>
        <Image Source="{StaticResource TestImg}" />
    </Grid>
</Window>
Related