Ok, here is my problem:
I have created a UserControl named MultiImage, which is composed by a two images, one bigger than the other.
What I am trying to do in the MainWindow is that, when you press a given RadioButton, one of the two images changes it source (2 RadioButtons change the big image and 3 change the little one). In the design view of the MultiImage class I can see the elements, but in the design view of the MainWindow, the object doesn't appear, and once you start the application it keeps not appearing, even if you click on the RadioButtons.
The code is the following:
MainWindow.xaml
<Window x:Class="MultiElementImage.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MultiElementImage"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:MultiImage x:Name="image1" Width="Auto" Height="Auto" Margin="10,10,208,10" />
<RadioButton Content="Laptop" GroupName="mainIcon" HorizontalAlignment="Left" Margin="335,97,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked_1"/>
<RadioButton Content="Trash can" GroupName="mainIcon" HorizontalAlignment="Left" Margin="335,117,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked_2"/>
<RadioButton Content="Warning" GroupName="stateIcon" HorizontalAlignment="Left" Margin="335,158,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked_3"/>
<RadioButton Content="Battery" GroupName="stateIcon" HorizontalAlignment="Left" Margin="335,178,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked_4"/>
<RadioButton Content="Error" GroupName="stateIcon" HorizontalAlignment="Left" Margin="335,198,0,0" VerticalAlignment="Top" Checked="RadioButton_Checked_5"/>
</Grid>
</Window>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
{
image1.mainIcon.Source = new BitmapImage(new Uri("Images/laptop.png", UriKind.Relative));
}
private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
{
image1.mainIcon.Source = new BitmapImage(new Uri("Images/trashcan.png", UriKind.Relative));
}
private void RadioButton_Checked_3(object sender, RoutedEventArgs e)
{
image1.statusIcon.Source = new BitmapImage(new Uri("Images/warning.png", UriKind.Relative));
}
private void RadioButton_Checked_4(object sender, RoutedEventArgs e)
{
image1.statusIcon.Source = new BitmapImage(new Uri("Images/battery.png", UriKind.Relative));
}
private void RadioButton_Checked_5(object sender, RoutedEventArgs e)
{
image1.statusIcon.Source = new BitmapImage(new Uri("Images/null.png", UriKind.Relative));
}
}
MultiImage.xaml
<UserControl x:Class="MultiElementImage.MultiImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Image Name="mainIcon" HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="300" Source="Images/laptop.png"/>
<Image Name="statusIcon" HorizontalAlignment="Left" Height="Auto" Margin="190,10,0,0" VerticalAlignment="Top" Width="Auto" Source="Images/null.png"/>
</Grid>
</UserControl>
MultiImage.xaml.cs
public partial class MultiImage : UserControl
{
public MultiImage()
{
this.mainIcon = new Image();
this.mainIcon.Source = new BitmapImage(new Uri("Images/laptop.png", UriKind.Relative));
this.statusIcon = new Image();
this.statusIcon.Source = new BitmapImage(new Uri("Images/warning.png", UriKind.Relative));
}
}
I have tried putting 2 Image objects and changing them with the RadioButtons to check if the route for the images is correct, and it worked, but I want to use the UserControl so I can easily put the status icon wherever I need. Any thoughts about what could be happening?
Thanks in advance!