locked
I would like to know how to load an image externally url RRS feed

  • Question

  • I would like to know how to load an image externally url

    <Button Name="StartGameBtn" HorizontalAlignment="Left" Margin="686,487,0,0" VerticalAlignment="Top" Width="180" Height="69" Background="{x:Null}" Click="StartGameBtn_Click" Grid.ColumnSpan="2" DataContext="{Binding}">
                <Button.Template>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <StackPanel>
                            <Image Name="Close2" Source="Resources/gamestart_hover.bmp" Stretch="Fill" Visibility="Collapsed" />
                            <Image Name="Close1" Source="Resources/gamestart.bmp" Stretch="Fill" Visibility="Visible" />
                        </StackPanel>
                        <ControlTemplate.Triggers>
                            <Trigger Property="UIElement.IsMouseOver" Value="True">
                                <Setter TargetName="Close2" Property="UIElement.Visibility" Value="Visible" />
                                <Setter TargetName="Close1" Property="UIElement.Visibility" Value="Collapsed" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Button.Template>
            </Button>

    this code is loaded from xaml

    I am trying to load the images externally url from xaml.cs
    but I have not been able to achieve it

    try using this code

    Uri uri = new Uri(AppDomain.CurrentDomain.BaseDirectory + strFormattedDate + @"\start.png", UriKind.RelativeOrAbsolute);
                   Close1.ImageSource = BitmapFrame.Create(uri);  
    but I don't have close1 reading, since it doesn't seem to exist to me

    can you tell me what I'm doing wrong

    Tuesday, August 25, 2020 8:12 AM

All replies

  • What do you mean "I don't have close1 reading"? It may be you have a malformed path e.g.

    using static System.IO.Path

    ...

    Combine(AppDomain.CurrentDomain.BaseDirectory, strFormattedDate, "start.png");

    And that strFormattedDate is acceptable for a valid path.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, August 25, 2020 10:56 AM
  • This forum is for C#-specific questions only. Please post questions related to using XAML and WPF in the new Microsoft Q&A forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, August 25, 2020 1:49 PM