Image disappears when running the project

Asked

Viewed 50 times

1

Good time people, I’m having problems using an image using WPF, I’m trying to use Uri to instantiate the image and run the project, but an Isfrozen error is false and does not run the project, using and I tried to use the normal mode below

<Window x:Class="curso.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:curso"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" 
        mc:Ignorable="d"
         TextElement.Foreground="{DynamicResource MaterialDesignBody}"
            TextElement.FontWeight="Regular"
         TextElement.FontSize="13"
         TextOptions.TextFormattingMode="Ideal"
         TextOptions.TextRenderingMode="Auto"
         Background="{DynamicResource MaterialDesignPaper}"
         FontFamily="{DynamicResource MaterialDesignFont}" Height="600" Width="1024" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None">


    <Window.Resources>
        <Storyboard x:Key="AbrirMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="200"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="70"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="FecharMenu">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="GridMenu">
                <EasingDoubleKeyFrame KeyTime="0" Value="70"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="200"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>

    <Window.Triggers>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonAbrir">
            <BeginStoryboard Storyboard="{StaticResource AbrirMenu}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="ButtonFecharMenu">
            <BeginStoryboard Storyboard="{StaticResource FecharMenu}"/>
        </EventTrigger>
    </Window.Triggers>



    <Grid>

        <Grid Height="30" VerticalAlignment="Top" Background="#FF9D6ED7">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10,0">


                <Button x:Name="ButtonMinimizar" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="25" Height="26"  Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Click="ButtonMinimizar_Click">
                    <materialDesign:PackIcon Kind="Minus" RenderTransformOrigin="-0.812,0.44"/>
                </Button>

                <Button x:Name="ButtonMaximizar" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="25" Height="26"  Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center"  Click="ButtonMaximizar_Click">
                    <materialDesign:PackIcon Kind="ArrowExpand" RenderTransformOrigin="-0.812,0.44"/>
                </Button>

                <Button x:Name="ButtonFechar" Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="25" Height="26"  Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Click="ButtonFechar_Click">
                    <materialDesign:PackIcon Kind="Power" RenderTransformOrigin="-0.812,0.44" VerticalAlignment="Center"/>
                </Button>
            </StackPanel>
        </Grid>

        <Grid x:Name="GridMenu" Width="70" HorizontalAlignment="Left">
            <Grid.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFD8C8C8" Offset="1"/>
                    <GradientStop Color="#FFA09D9D" Offset="0"/>
                </LinearGradientBrush>
            </Grid.Background>
            <Grid.RowDefinitions>
                <RowDefinition Height="100"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.Effect>
                <DropShadowEffect BlurRadius="20" Color="#FFA09898" RenderingBias="Quality" ShadowDepth="1"/>
            </Grid.Effect>
            <Grid Background="#FFa46fe4">

                <Button x:Name="ButtonAbrir"  Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="25" Height="26"  Background="{x:Null}" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="White" Visibility="Collapsed" Click="ButtonAbrir_Click">
                    <materialDesign:PackIcon Kind="ArrowLeft" RenderTransformOrigin="0.396,0.544" />
                </Button>
                <Button x:Name="ButtonFecharMenu"  Style="{StaticResource MaterialDesignFloatingActionMiniAccentButton}" Width="25" Height="26"  Background="{x:Null}" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="White" Click="ButtonFecharMenu_Click">
                    <materialDesign:PackIcon Kind="Menu" RenderTransformOrigin="0.396,0.544" />
                </Button>
                <Viewbox>
                    <Image Source="assets/logo.png"></Image>
                </Viewbox>
            </Grid>
            <StackPanel Grid.Row="1">
                <Button x:Name="ButtonInicio" Margin="10" Background="#FF7E2AE2" BorderBrush="#FF7E2AE2" Click="ButtonInicio_Click" >
                    <Grid Width="150">
                        <materialDesign:PackIcon Kind="ViewDashboard" VerticalAlignment="Center"/>
                        <TextBlock HorizontalAlignment="Center" Text="Inicio"/>
                    </Grid>
                </Button>

                <Button  x:Name="ButtonQuarto1" Margin="10" Background="#FF7E2AE2" BorderBrush="#FF7E2AE2" Click="ButtonQuarto1_Click">
                    <Grid Width="150">
                        <materialDesign:PackIcon Kind="bed" VerticalAlignment="Center"/>
                        <TextBlock HorizontalAlignment="Center" Text="Quarto 1"/>
                    </Grid>
                </Button>

                <Button x:Name="ButtonQuarto2" Margin="10" Background="#FF7E2AE2" BorderBrush="#FF7E2AE2" Click="ButtonQuarto2_Click">
                    <Grid Width="150">
                        <materialDesign:PackIcon Kind="bed" VerticalAlignment="Center"/>
                        <TextBlock HorizontalAlignment="Center" Text="Quarto 2"/>
                    </Grid>
                </Button>

                <Button x:Name="ButtonQuarto3" Margin="10" Background="#FF7E2AE2" BorderBrush="#FF7E2AE2" Click="ButtonQuarto3_Click">
                    <Grid Width="150">
                        <materialDesign:PackIcon Kind="bed" VerticalAlignment="Center"/>
                        <TextBlock HorizontalAlignment="Center" Text="Quarto 3"/>
                    </Grid>
                </Button>

                <Button x:Name="ButtonCozinha" Margin="10" Background="#FF7E2AE2" BorderBrush="#FF7E2AE2" Click="ButtonCozinha_Click">
                    <Grid Width="150">
                        <materialDesign:PackIcon Kind="Kitchen" VerticalAlignment="Center"/>
                        <TextBlock HorizontalAlignment="Center" Text="Cozinha "/>
                    </Grid>
                </Button>
            </StackPanel>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="15*"/>
                <RowDefinition Height="277*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="35*"/>
                <ColumnDefinition Width="117*"/>
                <ColumnDefinition Width="360*"/>
            </Grid.ColumnDefinitions>

            <Image  Source="assets/logo.png" Grid.Column="2" Margin="31,93,264,92" Grid.Row="1">
            </Image>

            <Label Content="Bem vindo!" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{x:Null}" Foreground="#DDE23939" FontSize="40" FontFamily="Impact" Margin="149,10,0,0" Grid.Row="1"/>

        </Grid>

    </Grid>

</Window>

however image appears in the design, but when running the project the image simply goes away... someone knows some solution?

These are my directories:

Diretórios

  • Heitor! Could you please attach in question some images of your project directories and code where this error? I thank you in advance.

  • Also send the output error message.

  • https://pastebin.com/bKV509yv this is the code Pastebin, https://imgur.com/GUznEYL to print with directories and the error using bitmap image is: The specified value of type 'System.Windows.Media.Imaging.Bitmapimage' must have Isfrozen set to false for modification.

  • Put the directory image in the question and code should not be as image.

  • Ever tried to set directly IsFrozen="false" inside <Image>.

  • try using patterns like this: <Image x:Name="img1" Stretch="Fill" Stretchdirection="Both" Grid.Column="2" Margin="192,98,235.922,223.403" Grid.Row="1" Source="Assets/logo.png"/>

  • Avoid using Viewbox, stay tuned for vertical and horizontal anchoring and strech in your image.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.