我有一个多 xaml metro 应用程序。我想通过单击按钮在 xaml 之间切换。
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Window.Current.Content = new BlankPage1();
this.InitializeComponent();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Window.Current.Content = new Sudoku.sudoku();
Window.Current.Activate();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
TextTwist.text_twist ob= new TextTwist.text_twist();
ob.InitializeComponent();
Window.Current.Content = ob;
}
这是具有按钮的主要 xaml 的逻辑代码。 现在,当我单击 button1 (/button2/button3) 时,相应的 xaml 出现在屏幕上,但未加载关联的图像。 否则它们在设计器中是完全可见的。
请帮帮我。
这是 xaml 片段的 1
<Grid x:Name="gridMain">
<Grid.Background>
<ImageBrush ImageSource="Assets/textTwist/blue_back.png"/>
</Grid.Background>
<ListView x:Name="lv" HorizontalAlignment="Left" Height="565" Margin="49,99,0,0" VerticalAlignment="Top" Width="315" SelectionChanged="ListView_SelectionChanged_1" Opacity="0.95" FontSize="128">
<ListView.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="1"/>
<GradientStop Color="#FF9CF147" Offset="0.261"/>
</LinearGradientBrush>
</ListView.Background>
</ListView>
<TextBox x:Name="txtblk" HorizontalAlignment="Left" Margin="436,207,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="126" Width="731" FontSize="72" AcceptsReturn="True" FontWeight="Bold" BorderThickness="0" Foreground="#FFF01D1D" CharacterSpacing="120">
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="White" Offset="0.874"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
<Button x:Name="btnSubmit" Content="Submit Word" HorizontalAlignment="Left" Margin="874,479,0,0" VerticalAlignment="Top" Width="293" Click="btnSubmit_Click" Height="96" FontSize="36" FontWeight="Normal" FontFamily="Segoe Print">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="#FF7DE09C" Offset="0.926"/>
</LinearGradientBrush>
</Button.Background>
</Button>
<Image x:Name="imgWrong" HorizontalAlignment="Left" Height="277" Margin="436,433,0,0" VerticalAlignment="Top" Width="280" Source="Assets/textTwist/wronganswer.png" Stretch="UniformToFill" Visibility="Collapsed"/>
<Image x:Name="imgRight" HorizontalAlignment="Left" Height="277" Margin="436,433,0,0" VerticalAlignment="Top" Width="280" Source="Assets/textTwist/rightanswer.png" Visibility="Collapsed"/>
<Image HorizontalAlignment="Left" Height="146" Margin="480,28,0,0" VerticalAlignment="Top" Width="624" Source="Assets/textTwist/text-twist-turbo-art.jpg" Stretch="UniformToFill"/>
</Grid>
相关图像是网格背景图像、按钮图像等。
最佳答案
使用 ms-appdata 或 ms-appx 格式设置图像源
<Image Source="ms-appdata:///local/myFileNotInTheAppPackage.png"/>
<Image Source="ms-appx:///Assets/myFilePartOfMyAppPackage.png"/>
关于c# - 地铁用户界面 : I'm switching xaml but images not loading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10803700/